c# file download webclient access-denied

c# - No se puede acceder al archivo-WebClient.DownloadFile



access-denied (4)

La aplicación probablemente no tiene permiso para escribir en esa carpeta. Si se trata de una aplicación cliente, intente ejecutarla como administrador. De lo contrario, cambie los permisos en ''c: / Games / Name / libs'' a control total para todos.

Así que he buscado la respuesta varias veces y me he entrometido con cosas de permisos en vano, pero este código todavía no me permite descargar un archivo a una ruta especificada.

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");

Siempre me da: "Acceso a la ruta ''c: / Games / Name / libs'' denegado".

También tenga en cuenta que con Windows XP SP3.


Puede usar el código a continuación para ver si tiene permiso de escritura en la carpeta, si no configuró la regla de falla usando setaccesscontrol antes de descargar

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; }


Si se niega el acceso a allí, intente ejecutarlo como administrador.

Si no funciona, vaya a la carpeta C:/Games/Name/libs , haga clic derecho y vaya a Propiedades. Elija la pestaña "Seguridad", seleccione en la lista superior el grupo de usuarios que ejecutará su programa. (Intente utilizar Users (YourName-PC/Users) ). Una vez seleccionado, haga clic en Editar en la parte inferior de la lista, y en la lista inferior, seleccione Full control en Allow .


Hola, probé el código anterior localmente y obtuve el mismo error "Acceso denegado":

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

Intente especificar el nombre del archivo al final del directorio, guarda localmente sin problemas cuando lo ejecuté:

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