contains empty string
I would like to write CAML query for SharePoint 2007 which have Contains query.
The only problem is that I want to use logic like:
If my search query has value, search for that with contains query If my search query is empty, select all items from list
I have tried with several queries (this is my null case):
<Query>
<Where>
<Or>
<IsNull>
<FieldRef Name="ImageFilter"/>
</IsNull>
<Contains>
<FieldRef Name='ImageFilter'></FieldRef>
<Value Type='Text'></Value>
</Contains>
</Or>
</Where>
</Query>
And
<Query>
<Where>
<Contains>
<FieldRef Name='ImageFilter'></FieldRef>
<Value Type='Text'></Value>
</Contains>
</Where>
</Query>
But nothing works,
Could you please help me with that?
If I understand this correctly, if you have a search query passed to whatever function is generating the CAML query, you want use the search term to find items that contain that search term. If no search term is present, you want to return all items. While I'm not sure what you're using to generate your CAML, the easiest way to do this is to not include the Query in your call if the search term is not included. If there is a search term, then this should work
<Query>
<Where>
<Contains>
<FieldRef Name='ImageFilter'>
<Value Type='Text'>{searchterm}</Value>
</Contains>
</Where>
</Query>
Where {searchterm} is the term you're looking for.
链接地址: http://www.djcxy.com/p/64146.html上一篇: 使用CAML查询获取特定的SharePoint Office 365列表项目?
下一篇: 包含空字符串