简体   繁体   English

查询未返回预期结果(CAML)

[英]Query not returning expected results(CAML)

I am trying to remove an attachment from a list of attachments using the CAML, however; 我正在尝试使用CAML从附件列表中删除附件; when I do the query it always returns both of my files. 当我执行查询时,它总是返回我的两个文件。 I only need to get the file of the current one using the passed in value as the parameter. 我只需要使用传入的值作为参数来获取当前文件的文件。

SP.List list = context.Web.Lists.GetByTitle("TempAttachments");

 // Query
            SP.CamlQuery query = new SP.CamlQuery();
            query.ViewXml =
                 "<Query><Where><Or>"
                + "<BeginsWith>"
                // Job Note Matches
                + "<FieldRef Name=\"FileRef\"/>"
                + "<Value Type=\"Text\"/>" + ID + "_</Value>"
                + "</BeginsWith>"
                // OR Date Modified is older than one day.
                + "<Lt>"
                + "<FieldRef Name=\"Modified\"/>"
                + "<Value Type=\"DateTime\"/><Today OffsetDays=\"-1\" /></Value>"
                + "</Lt>"
                + "</Or>"
                + "</Where></Query>";

Could the Beginswith tag be the problem? 可能是Beginswith标签吗?

  1. Your CAML query needs to be wrapped in a View element when seeting the ViewXml . 看到ViewXml时,您的CAML查询需要包装在View元素中。

  2. Your Value tags are both malformed; 您的Value标签都格式不正确; you're closing the element in the opening tag, meaning you have malformed XML. 您正在关闭开始标记中的元素,这意味着您的XML格式有误。

  3. Your query has an underscore at the end of the value you specify for the file name, but in the examples you mentioned in comments , your actual files don't have one, so that shouldn't be there. 您在查询中为文件名指定的值的末尾有一个下划线,但是在您在注释中提到的示例 ,您的实际文件没有一个,因此不应在其中。

So your query can now become: 这样您的查询现在可以变成:

CamlQuery query = new CamlQuery();
query.ViewXml = string.Format(
@"<View>
  <Query>
    <Where>
      <Or>
        <BeginsWith>
          <FieldRef Name='FileRef'/>
          <Value Type='Text'>{0}</Value>
        </BeginsWith>
        <Lt>
          <FieldRef Name='Modified'/>
          <Value Type='DateTime'>
            <Today OffsetDays='-1'/>
          </Value>
        </Lt>
      </Or>
    </Where>
  </Query>
</View>
", ID);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM