Sharepoint动态caml查询问题?
我想基于查询字符串进行动态 caml 查询。让我用示例来解释一下,
我的查询字符串可以是任何内容
?cat=ABC&cat=ABD&cat=ABE...
?Cat=ABC
?Cat=ABC&cat=ABL
,所以不是。现在问题开始了
我想根据这个查询字符串查询我的共享点列表,
if (HttpContext.Current.Request.QueryString["cat"] != null)
{
string _cat = HttpContext.Current.Request.QueryString["cat"].ToString();
}
这样我的字符串包含
string _cat=ABC,AD,....all.
我想根据这些查询字符串查询我的共享点列表的所有查询,
where title=ABC and title=AD ....
如果只有一个,则 使用“AND”查询字符串然后仅 其中 title=ABC
....所以我希望我的查询字符串应该是动态的.... 知道如何实现这一点吗?
I want to dynamic caml query based on query string.Let me explain it with example
my query sting can be anything
?cat=ABC&cat=ABD&cat=ABE...
?Cat=ABC
?Cat=ABC&cat=ABL
so no. can be anything now the problem begins
I want to query my sharepoint list based on this query string
if (HttpContext.Current.Request.QueryString["cat"] != null)
{
string _cat = HttpContext.Current.Request.QueryString["cat"].ToString();
}
so this way my string contains all the query
string _cat=ABC,AD,....all.
I want to query my sharepoint list based on these query string and with "AND"
where title=ABC and title=AD ....
if there is only one query string then only
where title=ABC
....so I want my query string should be dynamic....
Any idea how to acheive this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
假设您正在谈论多选选择字段...很可能您每次都必须创建查询。
您的代码需要确定传入的类别数量,然后生成 CAML。例如,如果仅传递 ABC,您的查询将是(注意没有
标签):但是如果您通过 QueryString 传递了三个选择:ABC、ABD 和 ABE,您将get(注意每两个组周围有
标签):编辑:
Assuming you are talking about a Multi-select choice field... most likely you will have to create the query each time.
Your code is going to need to determine how many categories are passed in and then generate the CAML. For example, if only ABC is passed your query would be (notice there are no
<And>
tags):But if you have three choices passed in via QueryString: ABC, ABD, and ABE you would get (notice the
<And>
tags surround each group of two):Edit:
检查 http://camlex.codeplex.com 项目。它的创建正是为了简化使用 C# lambda 表达式创建动态 CAML 语句。另请查看我的帖子:基于以下内容构建动态 CAML 查询查询字符串参数
check http://camlex.codeplex.com project. It was created exactly for simplifying of creation of dynamic CAML statements using C# lambda expressions. Also check my post: Build dynamic CAML queries based on query string parameters
我开发了 C# 代码来构建动态查询。
就像这样
IList lstOfElement 是保存过滤器元素的自定义对象。您可以创建自己的对象并传递给此方法。
I have developed C# code to build dynamic query.
Its like this
IList lstOfElement is custom object which holds filter elements. You can create your own object and pass into this method.
当您有多个输入时创建 CAML 查询字符串的基本算法是:
,只需创建代码如果您有两个以上,则创建一个循环(伪代码,抱歉):
The basic algorithm for creating the CAML query string when you have multiple inputs is:
<And>
, just create the code<and>(value1)(value2)</and>
If you have more than two, you create a loop (pseudocode, sorry):
如果您讨厌使用 String Concat 方法,您必须尝试 JohnHolliday 的 Lib - CAML.NET,我在我的项目中使用它,它非常棒。
你也会喜欢的
If you hate doing it using the String Concat method, You got to Try the JohnHolliday's Lib - CAML.NET, I use it in my project and it just rocks.
You too will love it