我在Sharepoint中有一个自定义搜索webpart,它有7个过滤器。我正在使用CAML查询从Sharepoint列表中获取数据。我想编写一个广义的SPQuery,它将根据搜索参数筛选出数据。搜索参数是可选的。如果用户输入任何2个参数,那么我需要获取与这2个参数相对应的数据。我如何使用CAML Query来实现这一点?我无法思考了基于搜索参数生成我CAML查询广义办法的..如何在sharepoint中使用可选搜索值的caml查询
0
A
回答
0
实际上写的逻辑来动态生成spquery
1
这里解决的问题是一些代码我在Silverlight中使用基于搜索参数生成CAML查询。 也许它是有帮助的。
private ClientContext context;
private Microsoft.SharePoint.Client.List SampleSPList;
private Microsoft.SharePoint.Client.ListItemCollection SampleSPCollection;
//Load the List
void LoadList()
{
SampleSPList = context.Web.Lists.GetByTitle("Sample");
context.Load(SampleSPList);
CamlQuery query = new Microsoft.SharePoint.Client.CamlQuery();
string camlQueryXml = "";
bool existsWhere = false;
if (searchString.Text != "")
{
camlQueryXml = camlQueryXml + "<Contains><FieldRef Name='sampleString' /><Value Type='Text'>" + searchString.Text + "</Value></Contains>";
if (existsWhere == true) {
camlQueryXml = "<And>" + camlQueryXml + "</And>";
}
existsWhere = true;
}
if (searchTextArea.Text != "")
{
camlQueryXml = camlQueryXml + "<Contains><FieldRef Name='sampleTextArea' /><Value Type='Text'>" + searchTextArea.Text + "</Value></Contains>";
if (existsWhere == true)
{
camlQueryXml = "<And>" + camlQueryXml + "</And>";
}
existsWhere = true;
}
if (existsWhere == true) { camlQueryXml = "<View><Query><OrderBy><FieldRef Name='ID' /></OrderBy><Where>" + camlQueryXml + "</Where></Query></View>"; }
else { camlQueryXml = "<View><Query><OrderBy><FieldRef Name='ID' /></OrderBy></Query></View>"; }
query.ViewXml = camlQueryXml;
SampleSPCollection = SampleSPList.GetItems(query);
context.Load(SampleSPCollection);
context.ExecuteQueryAsync(ListLoaded, ListLoadFailed);
}
相关问题
- 1. Sharepoint。使用CAML查询搜索项目
- 2. SharePoint CAML搜索修改者
- 3. Sharepoint CAML查询在ID字段上搜索文件夹
- 4. SharePoint列表使用CONTAINS的CAML查询
- 5. 的SharePoint CAML查询:值没有落入
- 6. 使用CAML查询在sharepoint中查询列表项
- 7. CAML查询肥皂的SharePoint
- 8. CAML查询的SharePoint 2013
- 9. 在Sharepoint中添加ListItem的CAML查询
- 10. SharePoint搜索查询
- 11. 如何使用可选搜索参数在SQL中创建搜索查询?
- 12. CAML查询SharePoint和/或
- 13. Sharepoint CAML日期查询
- 14. 使用CAML在SharePoint 2010列表中搜索附件
- 15. 在SharePoint 2010中使用UniqueID的Caml查询
- 16. sharepoint:使用日期时间值列上的caml查询检索记录
- 17. 如何使用自定义搜索字段中的CAML查询过滤列表?
- 18. CAML查询在SharePoint日历中检索日期范围
- 19. 如何使用CAML查询过滤SharePoint列表?
- 20. 在DataTable SharePoint上运行CAML查询
- 21. 如何使用CAML查询检查ContentType.Hidden?
- 22. SharePoint 2010搜索查询
- 23. 如何在SharePoint CAML查询中获取双记录?
- 24. 如何用caml查询从子文件夹中检索sharepoint列表项目
- 25. 加入使用CAML查询,SharePoint Online中的Web服务
- 26. 获取列表的SharePoint中使用CAML查询
- 27. 使用<In>标签在CAML查询的SharePoint
- 28. CAML查询的SharePoint列表列
- 29. 对T-SQL的SharePoint CAML查询
- 30. 的SharePoint CAML查询以下条件
你能举一个例子,说明输入可能是什么样子?您还需要参数之间的一些逻辑,您允许的选项有哪些? – 2010-06-07 20:54:53
我实际上通过编写逻辑来动态生成spquery来解决问题 – 2010-06-08 16:41:27