Failed to access file - WebClient.DownloadFile

So, I searched the answer many times and intervened in working with rights to no avail, but this code still does not allow downloading the file at the specified path.

WebClient client = new WebClient(); client.DownLoadFile("http://dl.dropbox.com/u/(My account)/Installer.jar", @"c:\Games\Name\libs"); client.DownLoadFile("http://dl.dropbox.com/u/(My account)/Name.zip", @"c:\Games\Name"); 

Always gives me: "Access to the path" c: \ Games \ Name \ libs "is denied."

Also note that using Windows XP SP3.

+7
source share
4 answers

Hi, I tried the above code locally and got the same "Access Denied" error:

 WebClient myWebClient = new WebClient(); myWebClient.DownloadFile("http://localhost:1929/2.png", @"C:\Z\) 

Try specifying the file name at the end of the directory, saving locally without problems when I run it:

 WebClient myWebClient = new WebClient(); myWebClient.DownloadFile("http://localhost:1929/2.png", @"C:\Z\FILENAME.jpg") 
+11
source

The application probably does not have permission to write to this folder. If this is a client application, try running it as an administrator. Otherwise, change the permissions on "c: \ Games \ Name \ libs" to full control for everyone.

+2
source

If access to it is denied, try running it as an administrator.

If it does not work, go to the C:\Games\Name\libs folder, right-click it and go to "Properties". Select the "Security" tab, select the group of users who will run your program in the upper list. (Try using Users (YourName-PC\Users) ). After selecting it, click "Edit" at the bottom of the list, and in the bottom list, select Full control in the Allow section.

+1
source

you can use the code below to find out if you have write permission in the folder if you don't set a crash rule using setaccesscontrol before downloading

  public static bool HaveWritePermissionsForFolder(string path) { var rules = Directory.GetAccessControl(Path.GetDirectoryName(Path.GetDirectoryName(path))).GetAccessRules(true, true, typeof(SecurityIdentifier)); bool allowwrite = false; bool denywrite = false; foreach (FileSystemAccessRule rule in rules) { if (rule.AccessControlType == AccessControlType.Deny && (rule.FileSystemRights & FileSystemRights.WriteData) == FileSystemRights.WriteData && (groups.Contains(rule.IdentityReference) || rule.IdentityReference.Value == sidCurrentUser) ) { denywrite = true; } if (rule.AccessControlType == AccessControlType.Allow && (rule.FileSystemRights & FileSystemRights.WriteData) == FileSystemRights.WriteData && (groups.Contains(rule.IdentityReference) || rule.IdentityReference.Value == sidCurrentUser) ) { allowwrite = true; } } if (allowwrite && !denywrite) return true; return false; } 
0
source

All Articles