C# 获取异常的caml查询有什么问题;无法完成此操作。请再试一次;?

C# 获取异常的caml查询有什么问题;无法完成此操作。请再试一次;?,c#,sharepoint,csom,caml,C#,Sharepoint,Csom,Caml,我正在SharePoint列表上实现caml查询! 我有5个条件,每2个条件放在一个标签中。但它仍然会收到此异常:“无法完成此操作。请重试!” 价值1 价值2 价值3 2019-06-22 2019-05-06 我的查询有什么问题?对于涉及多个字段的比较,它更像是自下而上的方法,首先比较两个字段,然后比较结果与第三个字段,然后比较结果与第四个字段,依此类推。因此,您的查询应该如下所示: <And> <Eq> <FieldRe

我正在SharePoint列表上实现caml查询! 我有5个条件,每2个条件放在一个标签中。但它仍然会收到此异常:“无法完成此操作。请重试!”


价值1
价值2
价值3
2019-06-22
2019-05-06

我的查询有什么问题?

对于涉及多个字段的比较,它更像是自下而上的方法,首先比较两个字段,然后比较结果与第三个字段,然后比较结果与第四个字段,依此类推。因此,您的查询应该如下所示:

      <And>
     <Eq>
        <FieldRef Name='fieldName1' />
        <Value Type='Text'>value1</Value>
     </Eq>
     <And>
        <Contains>
           <FieldRef Name='fieldName2' />
           <Value Type='Text'>value2</Value>
        </Contains>
        <And>
           <Contains>
              <FieldRef Name='fieldName3' />
              <Value Type='Note'>value3</Value>
           </Contains>
           <And>
              <Eq>
                 <FieldRef Name='fieldName4' />
                 <Value Type='Text'>value4</Value>
              </Eq>
              <Eq>
                 <FieldRef Name='fieldName5' />
                 <Value Type='Text'>value5</Value>
              </Eq>
           </And>
        </And>
     </And>
  </And>

价值1
价值2
价值3
价值4
价值5

对于涉及多个字段的比较,这更像是自下而上的方法,首先比较两个字段,然后比较结果与第三个字段,然后比较结果与第四个字段,依此类推。因此,您的查询应该如下所示:

      <And>
     <Eq>
        <FieldRef Name='fieldName1' />
        <Value Type='Text'>value1</Value>
     </Eq>
     <And>
        <Contains>
           <FieldRef Name='fieldName2' />
           <Value Type='Text'>value2</Value>
        </Contains>
        <And>
           <Contains>
              <FieldRef Name='fieldName3' />
              <Value Type='Note'>value3</Value>
           </Contains>
           <And>
              <Eq>
                 <FieldRef Name='fieldName4' />
                 <Value Type='Text'>value4</Value>
              </Eq>
              <Eq>
                 <FieldRef Name='fieldName5' />
                 <Value Type='Text'>value5</Value>
              </Eq>
           </And>
        </And>
     </And>
  </And>

价值1
价值2
价值3
价值4
价值5

我犯了错误,用递归算法进行查询。如果有人帮助提高it生产率,我会很高兴:

public static void main()
{
    string NestedQuery = "";
    int NestedQueryCounter = 0;
    string query = "<View><Query><Where>";
    var whereClauses = new List<string>();
    whereClauses.Add(SetupQueryExpression("FirstFiled", FirstValue, "Text", "Eq"));
    whereClauses.Add(SetupQueryExpression("SecondFiled",SecondValue, "Text", "Contains"));
    whereClauses.Add(SetupQueryExpression("ThirdField", ThirdValue, "Text", "Contains"));
    whereClauses.Add(SetupQueryExpression("ForthField", ForthValue, "DateTime", "Eq", "IncludeTimeValue='false'"));
    whereClauses.Add(SetupQueryExpression("FifthField",FifthValue, "DateTime", "Eq", "IncludeTimeValue='false'"));
    NestedWhereClauses(whereClauses, "<And>", "</And>");
    query += NestedQuery;
    query += "</Where></Query></View>"; 
}

private string SetupQueryExpression(string fieldName, string fieldValue, string dataType, string condition, 
            string extraValueCondition = "")
{
    string query = @"<{0}>
                         <FieldRef Name='{1}' /><Value Type='{2}' {4}>{3}</Value>
                     </{0}>";
    return string.Format(query, condition, fieldName, dataType, fieldValue, extraValueCondition);
}

private void NestedWhereClauses(List<string> whereCalauses, string mainCondition, string endMainCondition)
{
    if (2 == whereCalauses.Count)
    {
        NestedQuery += mainCondition;
        NestedQuery += whereCalauses[0];
        NestedQuery += whereCalauses[1];
        NestedQuery += endMainCondition;
        for (int counter = 0; counter < NestedQueryCounter; counter++)
            NestedQuery += endMainCondition;
    }
    else
    {
        NestedQueryCounter++;
        NestedQuery += mainCondition;
        NestedQuery += whereCalauses[0];
        whereCalauses.RemoveAt(0);
        NestedWhereClauses(whereCalauses, mainCondition, endMainCondition);
    }
}
publicstaticvoidmain()
{
字符串NestedQuery=“”;
int NestedQueryCounter=0;
字符串查询=”;
var where子句=新列表();
其中添加(SetupQueryExpression(“firstfield”、FirstValue、“Text”、“Eq”);
其中添加(SetupQueryExpression(“secondfield”,SecondValue,“Text”,“Contains”);
其中添加(SetupQueryExpression(“ThirdField”,ThirdValue,“Text”,“Contains”);
其中添加(SetupQueryExpression(“ForthField”,ForthValue,“DateTime”,“Eq”,“IncludeTimeValue='false'));
其中添加(SetupQueryExpression(“第五个字段”、“第五个值”、“日期时间”、“Eq”、“IncludeTimeValue='false'));
嵌套Where条款(Where条款,“,”);
query+=NestedQuery;
查询+=“”;
}
私有字符串SetupQueryExpression(字符串字段名、字符串字段值、字符串数据类型、字符串条件、,
字符串extraValueCondition=“”)
{
字符串查询=@“
{3}
";
返回string.Format(查询、条件、字段名、数据类型、字段值、extraValueCondition);
}
私有void nestedWhere子句(列出WhereCalaues、string mainCondition、string endMainCondition)
{
if(2==wherecalaues.Count)
{
NestedQuery+=mainCondition;
NestedQuery+=whereCalauses[0];
NestedQuery+=whereCalauses[1];
NestedQuery+=endMainCondition;
for(int counter=0;计数器
我犯了错误,用递归算法进行查询。如果有人帮助提高it生产率,我会很高兴:

public static void main()
{
    string NestedQuery = "";
    int NestedQueryCounter = 0;
    string query = "<View><Query><Where>";
    var whereClauses = new List<string>();
    whereClauses.Add(SetupQueryExpression("FirstFiled", FirstValue, "Text", "Eq"));
    whereClauses.Add(SetupQueryExpression("SecondFiled",SecondValue, "Text", "Contains"));
    whereClauses.Add(SetupQueryExpression("ThirdField", ThirdValue, "Text", "Contains"));
    whereClauses.Add(SetupQueryExpression("ForthField", ForthValue, "DateTime", "Eq", "IncludeTimeValue='false'"));
    whereClauses.Add(SetupQueryExpression("FifthField",FifthValue, "DateTime", "Eq", "IncludeTimeValue='false'"));
    NestedWhereClauses(whereClauses, "<And>", "</And>");
    query += NestedQuery;
    query += "</Where></Query></View>"; 
}

private string SetupQueryExpression(string fieldName, string fieldValue, string dataType, string condition, 
            string extraValueCondition = "")
{
    string query = @"<{0}>
                         <FieldRef Name='{1}' /><Value Type='{2}' {4}>{3}</Value>
                     </{0}>";
    return string.Format(query, condition, fieldName, dataType, fieldValue, extraValueCondition);
}

private void NestedWhereClauses(List<string> whereCalauses, string mainCondition, string endMainCondition)
{
    if (2 == whereCalauses.Count)
    {
        NestedQuery += mainCondition;
        NestedQuery += whereCalauses[0];
        NestedQuery += whereCalauses[1];
        NestedQuery += endMainCondition;
        for (int counter = 0; counter < NestedQueryCounter; counter++)
            NestedQuery += endMainCondition;
    }
    else
    {
        NestedQueryCounter++;
        NestedQuery += mainCondition;
        NestedQuery += whereCalauses[0];
        whereCalauses.RemoveAt(0);
        NestedWhereClauses(whereCalauses, mainCondition, endMainCondition);
    }
}
publicstaticvoidmain()
{
字符串NestedQuery=“”;
int NestedQueryCounter=0;
字符串查询=”;
var where子句=新列表();
其中添加(SetupQueryExpression(“firstfield”、FirstValue、“Text”、“Eq”);
其中添加(SetupQueryExpression(“secondfield”,SecondValue,“Text”,“Contains”);
其中添加(SetupQueryExpression(“ThirdField”,ThirdValue,“Text”,“Contains”);
其中添加(SetupQueryExpression(“ForthField”,ForthValue,“DateTime”,“Eq”,“IncludeTimeValue='false'));
其中添加(SetupQueryExpression(“第五个字段”、“第五个值”、“日期时间”、“Eq”、“IncludeTimeValue='false'));
嵌套Where条款(Where条款,“,”);
query+=NestedQuery;
查询+=“”;
}
私有字符串SetupQueryExpression(字符串字段名、字符串字段值、字符串数据类型、字符串条件、,
字符串extraValueCondition=“”)
{
字符串查询=@“
{3}
";
返回string.Format(查询、条件、字段名、数据类型、字段值、extraValueCondition);
}
私有void nestedWhere子句(列出WhereCalaues、string mainCondition、string endMainCondition)
{
if(2==wherecalaues.Count)
{
NestedQuery+=mainCondition;
NestedQuery+=whereCalauses[0];
NestedQuery+=whereCalauses[1];
NestedQuery+=endMainCondition;
for(int counter=0;计数器