为多个输入查询 SharePoint 列表时出现 CAML 错误
CAML error when querying SharePoint List for more than one input
我有一个 CAML
查询,它从 SharePoint
列表中检索数据。它通过 1 个输入,但当有 2 个或更多时失败。
错误:
Microsoft.SharePoint.SPException: One or more field types are not
installed properly. Go to the list settings page to delete these
fields. ---> System.Runtime.InteropServices.COMException: One or more
field types are not installed properly. Go to the list settings page
to delete these fields.
经过研究,可能的原因可能是 SharePoint 列不匹配 InternalName
。但是,查询设法针对 1 个输入执行,而不是 2 个或更多输入。
根据下面的查询示例,我对 FAIL
个案例的格式是否有误?
1.通过:
<Where>
<And>
<Eq>
<FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
</Eq>
<Neq>
<FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Where>
2。失败:
<Where>
<And>
<Eq>
<And>
<Or>
<Eq>
<FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
</Eq>
<Eq>
<FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
</Eq>
</Or>
<Neq>
<FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Eq>
</And>
</Where>
3。失败:
<Where>
<And>
<Eq>
<And>
<Or>
<FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
<FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
</Or>
<Neq>
<FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Eq>
<Neq>
<FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Where>
是CAML查询的问题,我将代码修改如下,供大家参考。
string siteUrl = "http://sp2013";
string listTitle = "DL";
string viewName="Test";
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[listTitle];
SPView view=list.Views[viewName];
string orQuery = "<Or><Eq><FieldRef Name=\"Header1Ref\"/><Value Type=\"Text\">H1</Value></Eq><Eq><FieldRef Name=\"Header1Ref\"/><Value Type=\"Text\">H2</Value></Eq></Or>";
string subQuery = String.Format("<Neq><FieldRef Name =\"ContentType\"/><Value Type=\"Text\">{0}</Value></Neq>", "Document");
string queryText = String.Format("<Where><And>{0}{1}</And></Where>", orQuery, subQuery);
var query = new SPQuery(view)
{
Query = queryText,
ViewAttributes = "Scope=\"RecursiveAll\"",
ViewFields = @"<FieldRef Name='RecordTitle'/>",
};
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem item in items)
{
Console.WriteLine(item["RecordTitle"]);
}
Console.ReadKey();
}
}
CAML 查询如下。
<Where>
<And>
<Or>
<Eq><FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value></Eq>
<Eq><FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value></Eq>
</Or>
<Neq>
<FieldRef Name="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Where>
我有一个 CAML
查询,它从 SharePoint
列表中检索数据。它通过 1 个输入,但当有 2 个或更多时失败。
错误:
Microsoft.SharePoint.SPException: One or more field types are not installed properly. Go to the list settings page to delete these fields. ---> System.Runtime.InteropServices.COMException: One or more field types are not installed properly. Go to the list settings page to delete these fields.
经过研究,可能的原因可能是 SharePoint 列不匹配 InternalName
。但是,查询设法针对 1 个输入执行,而不是 2 个或更多输入。
根据下面的查询示例,我对 FAIL
个案例的格式是否有误?
1.通过:
<Where>
<And>
<Eq>
<FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
</Eq>
<Neq>
<FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Where>
2。失败:
<Where>
<And>
<Eq>
<And>
<Or>
<Eq>
<FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
</Eq>
<Eq>
<FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
</Eq>
</Or>
<Neq>
<FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Eq>
</And>
</Where>
3。失败:
<Where>
<And>
<Eq>
<And>
<Or>
<FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
<FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
</Or>
<Neq>
<FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Eq>
<Neq>
<FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Where>
是CAML查询的问题,我将代码修改如下,供大家参考。
string siteUrl = "http://sp2013";
string listTitle = "DL";
string viewName="Test";
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[listTitle];
SPView view=list.Views[viewName];
string orQuery = "<Or><Eq><FieldRef Name=\"Header1Ref\"/><Value Type=\"Text\">H1</Value></Eq><Eq><FieldRef Name=\"Header1Ref\"/><Value Type=\"Text\">H2</Value></Eq></Or>";
string subQuery = String.Format("<Neq><FieldRef Name =\"ContentType\"/><Value Type=\"Text\">{0}</Value></Neq>", "Document");
string queryText = String.Format("<Where><And>{0}{1}</And></Where>", orQuery, subQuery);
var query = new SPQuery(view)
{
Query = queryText,
ViewAttributes = "Scope=\"RecursiveAll\"",
ViewFields = @"<FieldRef Name='RecordTitle'/>",
};
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem item in items)
{
Console.WriteLine(item["RecordTitle"]);
}
Console.ReadKey();
}
}
CAML 查询如下。
<Where>
<And>
<Or>
<Eq><FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value></Eq>
<Eq><FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value></Eq>
</Or>
<Neq>
<FieldRef Name="ContentType"/><Value Type="Text">Document</Value>
</Neq>
</And>
</Where>