简体   繁体   English

CAML-WebService共享点

[英]CAML- WebService Sharepoint

Hello stackoverflow community 你好stackoverflow社区

I got a load of help from this forum. 我从这个论坛上得到了很多帮助。 Though this time i couldn't find. 虽然这次我找不到。

I Made an ASP.NET application and I try to use a SharePoint WebService to get some Items of a List. 我制作了一个ASP.NET应用程序,并尝试使用SharePoint WebService获取列表中的某些项。

So far i succeed in getting the whole list using CAML request, but i have to select the items between 2 given dates 到目前为止,我已经成功地使用CAML请求获取了整个列表,但是我必须选择2个给定日期之间的项目

I found a lot of help around this and I'm using this method to format the ISO 8601 date string : 我在这方面找到了很多帮助,并且正在使用这种方法来格式化ISO 8601日期字符串:

private string FormatDateForCAML(DateTime theDate)
{
    string result = theDate.ToString("yyyy-MM-ddTHH:mm:ssZ");
    return result;
}

And here is the CAML request building : 这是CAML请求构建:

System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
query.InnerXml = 
        "<Where>"+
            "<And>"+
              "<Geq>"+
                  "<FieldRef Name=\"startdate\" />"+
                  "<Value Type=\"DateTime\" IncludeTimeValue=\"True\">" + theStart + "</Value>" +
              "</Geq>"+
              "<Lt>" +
                  "<FieldRef Name=\"enddate\" />" +
                  "<Value Type=\"DateTime\" IncludeTimeValue=\"True\">" + theEnd+ "</Value>" +
              "</Lt>" +
            "</And>"+
        "</Where>";

I don't have any error return by this query : 我没有任何错误返回此查询:

System.Xml.XmlNode nodeListItems = listService.GetListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, null);

But the list returned is null though it shoudn't 但是返回的列表为空,尽管它不应

Thanks for any help. 谢谢你的帮助。

EDIT : I finally succeed, problem came from a wrong request here is the proper version 编辑:我终于成功了,问题来自错误的请求,这里是正确的版本

System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
query.InnerXml = 
        "<Where>"+
            "<And>"+
              "<Geq>"+
                  "<FieldRef Name=\"startdate\" />"+
                  "<Value Type=\"DateTime\" IncludeTimeValue=\"True\">" + theStart + "</Value>" +
              "</Geq>"+
              "<Lt>" +
                  "<FieldRef Name=\"startdate\" />" +
                  "<Value Type=\"DateTime\" IncludeTimeValue=\"True\">" + theEnd+ "</Value>" +
              "</Lt>" +
            "</And>"+
        "</Where>";

Thanks to Roqz I Used the CAML viewer,and I could get the problem : I had to compare the start date only ! 多亏了Roqz,我使用了CAML查看器,所以我得到了问题:我只需要比较开始日期!

Thank you both for help :) 谢谢你们的帮助:)

In my CAML Builder Tool a Query similar to yours does return the result it should. 在我的CAML Builder工具中,与您类似的查询会返回其应有的结果。 Query looks like: 查询看起来像:

<Query>
    <Where>
        <And>
          <Geq>
            <FieldRef Name="Created" />
            <Value IncludeTimeValue="TRUE" Type="DateTime">2013-04-01T19:35:49Z</Value>                 
          </Geq>
          <Lt>
            <FieldRef Name="Modified" /><Value IncludeTimeValue="TRUE" Type="DateTime">2013-05-24T19:36:46Z</Value>
          </Lt>
        </And>
     </Where>
</Query>

But as I remember, if you want to use this query in code than you do not need the surrounding tags. 但是我记得,如果您想在代码中使用此查询,则不需要周围的标签。 Have you checked that your date format is correct? 您检查日期格式是否正确? in your example I can't see the "Z" at the end. 在您的示例中,我看不到结尾的“ Z”。

Try to run your CAML query in a console application using full SharePoint object model with any clause you want like you want to filter on dates. 尝试使用完整的SharePoint对象模型在控制台应用程序中运行CAML查询,该模型包含您想要的任何要过滤日期的子句。 If your CAML works in full SharePoint object model it should ideally work as well when you try to fetch data using SharePoint Native Web Services. 如果您的CAML在完整的SharePoint对象模型中工作,则当您尝试使用SharePoint本机Web服务获取数据时,它在理想情况下也应该工作。

I wanted to add that this method : 我想补充一下这个方法:

private string FormatDateForCAML(DateTime theDate)
{
    string result = theDate.ToString("yyyy-MM-ddTHH:mm:ssZ");
    return result;
}

is equivalent to : 等效于:

private string FormatDateForCAML(DateTime theDate)
{
    string result = theDate.ToString("s");
    return result;
}

date.ToString("s") return a ISO.8601 date format string. date.ToString(“ s”)返回ISO.8601日期格式字符串。

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

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