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:
requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
To confirm, I also get a nice UAC popup when starting.
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:)
Function GetFolderSize(ByVal DirPath As String, ByVal includeSubFolders As Boolean) As
Long
Try
Dim size As Long = 0
Dim diBase As New DirectoryInfo(DirPath)
Dim files() As FileInfo
If includeSubFolders Then
files = diBase.GetFiles("", SearchOption.AllDirectories)
Else
files = diBase.GetFiles("", SearchOption.TopDirectoryOnly)
End If
Dim ie As IEnumerator = files.GetEnumerator
While ie.MoveNext And Not abort
size += DirectCast(ie.Current, FileInfo).Length
End While
Return size
Catch ex As Exception
MsgBox("Error: " & ex.Message)
Return -1
End Try
End Function
This gives me an error saying "Error: access to the path c:\users\vincent\documents\my videos is denied."
My file copy:
my.computer.filesystem.copydirectory(filepath, newcopy, false)
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.
Anybody have a suggestion that might fix this? Thanks!