title: Get all folders and sub folders in SharePoint using Web Service
body: <p>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.</p>
  
  <p>So I added a Web Reference to SiteData.asmx to my project and found the following code:</p>
  
  <pre><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
  </code></pre>
  
  <p>I copied this code from a forum on <a href="http://msdn.microsoft.com/en-us/library/ms774758.aspx" rel="nofollow">msdn</a> 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.</p>
  
  <p>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</p>