2016-02-25 194 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;