0
我開發Silverlight Web部件。我有一個列表條目日誌。在這個列表中,我存儲了所有基本信息的條目。所有條目都成功保存。現在我想檢索其在進入日誌列表中創建這些條目的最大日期和最小日期。所以我用下面的代碼如何使用客戶端對象模型檢索SharePoint Server 2010中的最大日期和最小日期?
public void PopulateTimeLog(String paymentStatus, String currentUser, timeLogDelegate populateCombo)
{
timeLogDelegateClient = populateCombo;
ClientContext clientContext = ClientContext.Current;
List list = clientContext.Web.Lists.GetByTitle("Time Log");
string query = "<View>";
query += "<Query>";
query += "<Where>";
query += "<And>";
query += "<Eq>";
query += "<FieldRef Name='Author'></FieldRef>";
query += "<Value Type='Lookup'>" + currentUser + "</Value>";
query += "</Eq>";
query += "<Eq>";
query += "<FieldRef Name='Payment_x0020_Status'></FieldRef>";
query += "<Value Type='Text'>" + paymentStatus + "</Value>";
query += "</Eq>";
query += "</And>";
query += "</Where>";
query += "<OrderBy>";
query += "<FieldRef Name='Created' Ascending='False'></FieldRef>";
query += "</OrderBy>";
query += "</Query>";
query += "</View>";
CamlQuery Query = new CamlQuery();
Query.ViewXml = query;
listItemsTimeLog = list.GetItems(Query);
//clientContext.Load(list);
//clientContext.Load(listItemsTimeLog);
clientContext.Load(listItemsTimeLog, itms => itms.Include(
itm => itm["Created"]));
clientContext.ExecuteQueryAsync(HandleTimeLogRequestSucceeded, HandleTimeLogRequestFailed);
}
private void HandleTimeLogRequestSucceeded(object sender, ClientRequestSucceededEventArgs e)
{
////call back on the UI thread
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
{
timeLogDelegateClient(listItemsTimeLog);
});
}
在上面的代碼中,我將獲得listItemsTimeLog在索引0和最小日期listItemsTimeLog的最大日在最後一個索引。在上面的查詢中,我不想檢索listItemsTimeLog中的所有日期。我如何簡化上面的查詢,讓我得到的只有兩個字符串值 - 一個字符串將包含最大日期和其他字符串將包含mimimum日期。如果我可以通過網絡服務來完成,那麼對我來說也很好?我怎樣才能做到這一點 ?你能提供我任何代碼,以便我可以解決上述問題嗎?