2016-02-25 62 views
0

我沒有找到關於這方面的很多,使用Microsoft.SharePoint連接到SharePoint。通過vb.net連接到sharepoint

我在找的是簡單地查詢共享點並遍歷每個項目,檢查每個項目的文件大小,並注意項目是否超過閾值。

除了在WebBrowser對象中加載sharepoint和屏幕抓取之外,是否有任何方法可以做到這一點?

有沒有人有這個鏈接?

回答

0

我不是使用VB.net,但在C#代碼可以是這樣的。

class SharePointOperation : IDisposable 
{ 
    private ClientContext oContext; 
    private Web oWeb; 

    public SharePointOperation(string webUrl) 
    { 
     oContext = new ClientContext(webUrl); 
     oWeb = oContext.Web; 
    } 

    /// <summary> 
    /// Get list items 
    /// </summary> 
    /// <param name="listName"></param> 
    /// <param name="camlQuery"></param> 
    /// <param name="callback"></param> 
    public void GetListItems(string listName, string camlQuery, Action<ListItemCollection> callback) 
    { 
     ListItemCollectionPosition position = new ListItemCollectionPosition {PagingInfo = ""}; 
     ListItemCollection oItems; 
     List oList = oWeb.Lists.GetByTitle(listName); 

     do 
     { 
      CamlQuery oQuery = new CamlQuery { ViewXml = camlQuery }; 
      oQuery.ListItemCollectionPosition = position; 

      oItems = oList.GetItems(oQuery); 
      oContext.Load(oItems); 
      oContext.ExecuteQuery(); 
      callback(oItems); 
      position = oItems.ListItemCollectionPosition; 
     } while (position != null); 



    } 

    public void Dispose() 
    { 
     oContext.Dispose(); 
    } 
} 

我已經創建了一個SharePoint操作類來處理。要從列表中獲取數據,我可以這樣做。

string caml = "<View><RowLimit>10</RowLimit><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>Title value</Value></Eq></Where>/Query></View>"; 

using (SharePointOperation op = new SharePointOperation("https://url")) 
{ 
       op.GetListItems("List name",caml, (ListItemCollection items) => 
       { 
        // Code not extended for brevity 
        MessageBox.Show("Done"); 
       }); 
} 

最後一個參數是每次獲取數據時執行的操作。數據以區塊形式檢索,以避免使用大量項目的問題。無論如何,這只是一個想法。您可以將C#轉換爲VB.net,並且應該爲您工作。

要使用來自外部應用程序的SharePoint數據,請不要忘記添加對客戶端對象模型庫的引用。這些通常可以在C:\ Program Files \ Common Files \ microsoft shared \ Web Server Extensions \ 16 \ ISAPI中找到。只需添加引用Microsoft.SharePoint.Client.dll和Microsoft.SharePoint.Client.Runtime.dll

using Microsoft.SharePoint.Client;