2012-04-11 70 views
0

我想收集我的網址和描述存儲在列表中的一列從sharepoint,我不知道如何收集URL值。url sharepoint列表camlquery

這是我的代碼:

  var queryResultSaleListItems = clientContext.LoadQuery(listData); 

      clientContext.ExecuteQuery(); 

      //Read the Data into the Object 
      var TipsList = from Tips in queryResultSaleListItems 
          select Tips; 
      ObservableCollection<Tips> colTips = new ObservableCollection<Tips>(); 
      //Read Every List Item and Display Data into the DataGrid 
      foreach (SPSClient.ListItem item in TipsList) 
      { 

       var tips = new Tips(); 
       tips.TitleTip = item.FieldValues.Values.ElementAt(1).ToString(); 
       tips.App = item.FieldValues.Values.ElementAt(4).ToString(); 
       //should collect the url 
       tips.URL = item.FieldValues.Values.ElementAt(5).ToString(); 
       //should collect the description of the url 
       tips.URLdesc = item.FieldValues.Values.ElementAt(5).ToString(); 

       colTips.Add(tips); 
      } 
      ListboxTips.DataContext = colTips; 

以我表達其>

((Microsoft.SharePoint.Client.FieldUrlValue)(item.FieldValues.Values.ElementAt(5)))地址。

((Microsoft.SharePoint.Client.FieldUrlValue)(item.FieldValues.Values.ElementAt(5)))。說明您的幫助

謝謝,

+0

我的網址指的SharePoint使用哪個網址? – 2012-04-11 10:08:25

+0

在sharepoint列表中你可以創建一個列超鏈接類型..所以這是我的網址。 – user1315345 2012-04-11 11:50:23

回答

4

使用FieldUrlValue獲得hyperlink字段Client Object Model

使用下面的代碼:

 string server = "siteURL"; 
     var ctx = new ClientContext(server); 
     var web = ctx.Web; 
     var list = web.Lists.GetByTitle("CustomList"); 
     var listItemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery()); 

     ctx.Load(listItemCollection);      

     ctx.ExecuteQuery(); 

     foreach (Microsoft.SharePoint.Client.ListItem listItem in listItemCollection) 
     {     
      string acturlURL = ((FieldUrlValue)(listItem["URL"])).Url.ToString(); // get the Hyperlink field URL value 
      string actdesc = ((FieldUrlValue)(listItem["URL"])).Description.ToString(); // get the Hyperlink field Description value 
     }