2012-06-20 111 views
3

我正在開發一個Web應用程序,需要獲取SharePoint上的文件夾和子文件夾,並將其放在表示層次結構的TreeView上。 我的應用程序沒有運行在與SharePoint相同的服務器上,所以我認爲最好的方法是通過Web服務。使用Web服務獲取SharePoint中的所有文件夾和子文件夾

所以我添加的Web引用SiteData.asmx到我的項目,發現下面的代碼:

Private Sub GetSiteData() 
    Dim RootFolder As String = "http://mySharepointServer/site/doc_site" 
    Dim DirWSSP As String = "http://mySharePointServer/_vti_bin/SiteData.asmx" 


    'Definitions of TreeView 
    Dim tree As TreeView 
    Dim raiz As TreeNode 
    Dim no As TreeNode 

    tree = Page.FindControl("trvFolder") 
    raiz = New TreeNode(RootFolder) 
    tree.Nodes.Clear() 
    tree.Nodes.Add(raiz) 

    ' Definitions of web service 
    Dim service As New SP_SiteData.SiteData 

    service.Credentials = New System.Net.NetworkCredential("userID", "password", "domain") 


    Dim enArray() As SP_SiteData._sFPUrl 

    service.EnumerateFolder(RootFolder, enArray) 

    Dim en As SP_SiteData._sFPUrl 
    For Each en In enArray 
     If en.IsFolder Then 
      no = New TreeNode(en.Url) 
      raiz.ChildNodes.Add(no) 
     End If 
    Next 

End Sub 

我複製從一個論壇的代碼上msdn但不工作時,service.EnumerateFolder總是返回一個空數組,即enArray總是出現Nothing,並且出現錯誤:Object Reference未設置爲對象的實例。

此代碼適用? 還有另一種方法可以做到這一點? 我對web服務和web應用程序非常熟悉。 OBS:我正在使用Visual Studio 2010和SharePoint 2010

回答

1

我找到了使用Web服務Lists.asmx的解決方案。

問題是我在web開發非常新手,我對Sharepoint一無所知,所以我不知道如何使用Web服務。

問題是我提供了錯誤的網址。 URL必須如:

http://mysharepointsite/site/subsite_or_list/_vti_bin/Lists.asmx 

,我用

http://mysharepointsite/_vti_bin/Lists.asmx 

不同的是我調用Web服務lists.asmx的子網站。

我不知道的另一件事是,我所稱的文件夾實際上是在SharePoint中的列表,所以即時通訊方法getlistitems(),必須將列表名稱作爲參數。

反正獲得進一步的幫助,如果任何人有同樣的問題,因爲我不得不請點擊此鏈接:

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/99f3e9d0-6ecf-4b1d-8b68-d108f36aaacc

和代碼是在這裏從MSD: http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems(v=office.12)

很抱歉的壞英文....

謝謝大家

1

ListI通過web服務可以識別文件夾和文檔,你可以區分「ows_ContentType」屬性。在對象模型中,他們有一個IsFolder屬性。

IEnumerable<XElement> result = from child in root.Descendants(xns + "row") 
    where child.Attribute("ows_ContentType").Value == "Folder" 
    select child; 

此LINQ查詢可用於Web方法結果上僅返回文件夾類型。很容易看到,即使您不瞭解LINQ調用,如何將其更改爲「文檔」。

*相關說明「GetFolderCollection」的Web服務正在討論Sharepoint文件夾,它表示網站目錄文件夾。

相關問題