title: Can't access Documents folder from VB.net in Windows 7
body: <p>I've been struggling with this problem in VB.net for a while: whenever I try to access the My Documents, My video's or simular in Windows 7, I get an access denied error. The program that uses this code is a file-backup application, so it's important it can access everything. The app has admin rights, using this line:</p>
  
  <p>requestedExecutionLevel level="requireAdministrator" uiAccess="false" /></p>
  
  <p>To confirm, I also get a nice UAC popup when starting.</p>
  
  <p>The app accesses the files twice. Once to calculate the file size, and once to actually copy the files. Here is the file-size calculation code (that I found online:)</p>
  
  <blockquote>
    <p>Function GetFolderSize(ByVal DirPath As String, ByVal includeSubFolders As Boolean) As<br>
    Long<br>
           Try<br>
               Dim size As Long = 0<br>
               Dim diBase As New DirectoryInfo(DirPath)<br>
               Dim files() As FileInfo<br>
               If includeSubFolders Then<br>
                   files = diBase.GetFiles("<em>", SearchOption.AllDirectories)<br>
               Else<br>
                   files = diBase.GetFiles("</em>", SearchOption.TopDirectoryOnly)<br>
               End If<br>
               Dim ie As IEnumerator = files.GetEnumerator<br>
               While ie.MoveNext And Not abort<br>
                   size += DirectCast(ie.Current, FileInfo).Length<br>
              End While<br>
               Return size<br>
           Catch ex As Exception<br>
               MsgBox("Error: " &amp; ex.Message)<br>
               Return -1<br>
           End Try<br>
       End Function  </p>
  </blockquote>
  
  <p>This gives me an error saying "Error: access to the path c:\users\vincent\documents\my videos is denied."</p>
  
  <p>My file copy:</p>
  
  <blockquote>
    <p>my.computer.filesystem.copydirectory(filepath, newcopy, false)</p>
  </blockquote>
  
  <p>Returns the same error.
  Note: my OS is in Dutch so these error's may not be the exact same on an English OS: I translated them.</p>
  
  <p>Anybody have a suggestion that might fix this? Thanks!</p>