您的位置:首页 > 产品设计 > UI/UE

sharepoint中如何根据多个用户ID拼接SPQuery语句

2012-03-22 15:06 344 查看
这个是sharepoint中利用用户的id来拼接query语句进行查询,出入参数为一个string的数组,

可以用下面方法对数组中为空和重复的数据排除;

/// 排除数组中重复项和空项

/// </summary>

/// <param name="values"></param>

/// <returns></returns>

private static string[] getString(string[] values)

{

List<string> list = new List<string>();

for (int i = 0; i < values.Length; i++)

{

if (list.IndexOf(values[i].ToLower()) == -1 && values[i] != "")

{

list.Add(values[i]);

}

}

return list.ToArray();

}

/// <summary>

/// 根据收藏的id拼接query查询语句

/// </summary>

/// <param name="sharedocument"></param>

/// <returns></returns>

private static string getQuery(string[] sharedocument)

{

//当为1个的时候

string query = "";

if (sharedocument.Length == 1)

{

for (int i = 0; i < sharedocument.Length; i++)

{

query += "<Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='User'>" + sharedocument[i] + "</Value></Eq>";

}

}

//两个的时候

else if (sharedocument.Length == 2)

{

string newmessage = "";

for (int i = 0; i < sharedocument.Length; i++)

{

newmessage += "<Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='User'>" + sharedocument[i] + "</Value></Eq>"; }

query = "<Or>" + newmessage + "</Or>";

}

//大于两个的时候

else if (sharedocument.Length > 2)

{

//前两个id的链接

string query2 = "";

string newmessage2 = "";

for (int i = 0; i < 2; i++)

{

newmessage2 += "<Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='User'>" + sharedocument[i] + "</Value></Eq>"; }

query2 = "<Or>" + newmessage2 + "</Or>";

string query3 = "";

string newmessage3 = "";

for (int j = 2; j < sharedocument.Length; j++)

{

query3 += "<Or>";

newmessage3 += "<Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='User'>" + sharedocument[j] + "</Value></Eq></Or>";

}

query = query3 + query2 + newmessage3;

}

return query;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐