用于搜索页面 returns 网站中所有文件和文件夹的 CAML
CAML to search for pages returns all files and folders in a site
我正在尝试为 Sharepoint 2013 编写一个简单的 Web 部件,用于搜索特定内容类型的所有页面并输出其标题列表。我正在使用 CAML 查询来搜索它。但无论什么查询,我得到的结果只是这个 Sharepoint 站点中所有文件和文件夹的列表。
最后,我将 CAML 查询简化为一个简单的 "find everything that starts with the letter T",但结果仍然是输出站点根级别中的所有文件和文件夹。
我做错了什么?
protected override void CreateChildControls()
{
Label label1 = new Label();
try
{
SPQuery query = new SPQuery();
query.Query = @"<Query>
<Where>
<BeginsWith>
<FieldRef Name='Title'></FieldRef>
<Value Type='Text'>T</Value>
</BeginsWith>
</Where>
</Query>";
using (SPSite site = new SPSite("https://xxxxxx/sites/xxxxx/en/xxxx/"))
{
using (SPWeb web = site.OpenWeb())
{
PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web);
PublishingPageCollection collection = pubweb.GetPublishingPages(query);
//now output the results of the query
label1.Text = "Items: " + collection.Count.ToString();
for (int i = 0; i < collection.Count; i++)
{
label1.Text += collection[i].Title + "<br>";
}
}
}
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
Controls.Add(label1);
}
奇怪的是,你需要做两件事:
1) 去掉开始和结束标签;
2) 确保查询不以空行开始或结束。
然后结果会改变正确的。
我正在尝试为 Sharepoint 2013 编写一个简单的 Web 部件,用于搜索特定内容类型的所有页面并输出其标题列表。我正在使用 CAML 查询来搜索它。但无论什么查询,我得到的结果只是这个 Sharepoint 站点中所有文件和文件夹的列表。
最后,我将 CAML 查询简化为一个简单的 "find everything that starts with the letter T",但结果仍然是输出站点根级别中的所有文件和文件夹。
我做错了什么?
protected override void CreateChildControls()
{
Label label1 = new Label();
try
{
SPQuery query = new SPQuery();
query.Query = @"<Query>
<Where>
<BeginsWith>
<FieldRef Name='Title'></FieldRef>
<Value Type='Text'>T</Value>
</BeginsWith>
</Where>
</Query>";
using (SPSite site = new SPSite("https://xxxxxx/sites/xxxxx/en/xxxx/"))
{
using (SPWeb web = site.OpenWeb())
{
PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web);
PublishingPageCollection collection = pubweb.GetPublishingPages(query);
//now output the results of the query
label1.Text = "Items: " + collection.Count.ToString();
for (int i = 0; i < collection.Count; i++)
{
label1.Text += collection[i].Title + "<br>";
}
}
}
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
Controls.Add(label1);
}
奇怪的是,你需要做两件事:
1) 去掉开始和结束标签;
2) 确保查询不以空行开始或结束。
然后结果会改变正确的。