如何使用客户端对象模型从Sharepoint server 2010检索最大日期和最小日期



我正在开发silverlight web部件。我有一个单条目日志。在这个列表中,我存储了基本信息的所有条目。保存所有表项成功。现在,我想检索在Entry日志列表中创建这些条目的最大日期和最小日期。所以我使用下面的代码

    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);
        });
    }

在上面的代码中,我将获得索引0处listtitemstimelog中的最大日期和最后索引处listtitemstimelog中的最小日期。在上面的查询中,我不想检索listtitemstimelog中的所有日期。我怎样才能简化上面的查询,使我只得到两个字符串值-一个字符串将包含最大日期,另一个字符串将包含最小日期。如果我可以通过web服务来做,那么它对我来说也很好吗?我该怎么做呢?能否提供代码给我,以便我解决以上问题

您可以使用RowLimit,例如

马克思

<View>
  <Query>
    <Where>
      <And>
        <Eq>
          <FieldRef Name='Author'></FieldRef>
          <Value Type='Lookup'>[your use name]</Value>
        </Eq>
        <Eq>
          <FieldRef Name='Payment_x0020_Status'></FieldRef>
          <Value Type='Text'>[ your payment status]</Value>
        </Eq>
      </And>
    </Where>
    <OrderBy>
      <FieldRef Name='Created' Ascending='False'></FieldRef>
    </OrderBy>
  </Query>
 <RowLimit>1</RowLimit>
</View>
最小值

<View>
  <Query>
    <Where>
      <And>
        <Eq>
          <FieldRef Name='Author'></FieldRef>
          <Value Type='Lookup'>[your use name]</Value>
        </Eq>
        <Eq>
          <FieldRef Name='Payment_x0020_Status'></FieldRef>
          <Value Type='Text'>[ your payment status]</Value>
        </Eq>
      </And>
    </Where>
    <OrderBy>
      <FieldRef Name='Created' Ascending='True'></FieldRef>
    </OrderBy>
  </Query>
 <RowLimit>1</RowLimit>
</View>

相关内容

  • 没有找到相关文章

最新更新