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

这个是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;

         }

转载于:https://www.cnblogs.com/zhengfn/archive/2012/03/22/2411650.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值