簡體   English   中英

CAML-WebService共享點

[英]CAML- WebService Sharepoint

你好stackoverflow社區

我從這個論壇上得到了很多幫助。 雖然這次我找不到。

我制作了一個ASP.NET應用程序,並嘗試使用SharePoint WebService獲取列表中的某些項。

到目前為止,我已經成功地使用CAML請求獲取了整個列表,但是我必須選擇2個給定日期之間的項目

我在這方面找到了很多幫助,並且正在使用這種方法來格式化ISO 8601日期字符串:

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

這是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>";

我沒有任何錯誤返回此查詢:

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

但是返回的列表為空,盡管它不應

謝謝你的幫助。

編輯:我終於成功了,問題來自錯誤的請求,這里是正確的版本

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>";

多虧了Roqz,我使用了CAML查看器,所以我得到了問題:我只需要比較開始日期!

謝謝你們的幫助:)

在我的CAML Builder工具中,與您類似的查詢會返回其應有的結果。 查詢看起來像:

<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>

但是我記得,如果您想在代碼中使用此查詢,則不需要周圍的標簽。 您檢查日期格式是否正確? 在您的示例中,我看不到結尾的“ Z”。

嘗試使用完整的SharePoint對象模型在控制台應用程序中運行CAML查詢,該模型包含您想要的任何要過濾日期的子句。 如果您的CAML在完整的SharePoint對象模型中工作,則當您嘗試使用SharePoint本機Web服務獲取數據時,它在理想情況下也應該工作。

我想補充一下這個方法:

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

等效於:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM