I am developing a web application who needs to get the folders and sub folders who is on SharePoint and put on a TreeView representing the hierarchy.
My application is not running in the same server that SharePoint, so I think the best way to do this is through Web Services.
So I added a Web Reference to SiteData.asmx to my project and found the following code:
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
I copied this code from a forum on msdn but is not working, the service.EnumerateFolder always return an empty array, that is , enArray always comes Nothing and I get an error : Object Reference not set to an instance of an object.
This code works?
There is another way to do this?
I am very novice with web services and web applications.
OBS: I’m using Visual Studio 2010 and SharePoint 2010
I found the solution using the web service Lists.asmx.
The problem is I am very novice in web develpment and I don’t know nothing about Sharepoint, so i don’t knew how to use the web services.
The problem was I was providing the wrong url. The url must be like:
and I was using
The difference is I call the web Service
lists.asmxon subsite.Another thing I didn’t know, is that what I was calling the folders are actually lists in sharepoint, so im method
getlistitems(), must put the list Name as parameter.Anyway for futher help, if anybody have the same problem as i had follow this link :
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/99f3e9d0-6ecf-4b1d-8b68-d108f36aaacc
And the code are that here from msd:
http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems(v=office.12)
Sorry for the bad english….
Thanks everybody