Mit dem folgenden Code versuchen Sie, PDF-Dateien von Webseiten herunterzuladen und in einem vom Benutzer ausgewählten Ordner abzulegen. Jedes Mal, wenn es läuft, erhalte ich eine Nachricht, dass der Zugriff auf einen Pfad verweigert wird.System.UnauthorisedAccessException während der WebClient-Anfrage C#
Fehlermeldung:
[0] "Link was not downloaded due to: System.Net.WebException: An exception occurred during a WebClient request. ---> System.UnauthorizedAccessException: Access to the path ***** is denied.\r\n at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)\r\n at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)\r\n at System.Net.WebClient.DownloadFile(Uri address, String fileName)\r\n --- End of inner exception stack trace ---\r\n at System.Net.WebClient.DownloadFile(Uri address, String fileName)\r\n at System.Net.WebClient.DownloadFile(String address, String fileName)\r\n at TextFileToDownloadedPDF.Form1.DownloadPDF() in *****\\Form1.cs:line 103 link address: *address to download pdf, removed for security reasons* object {string}
Code:
string source = client.DownloadString(htmlLink);
string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
client.DownloadFile(htmlLink, destinationDirectory + title);
versucht, alle in den Foren suchen, aber keine Lösungen zu funktionieren scheint. Ich würde gerne wissen, was schief läuft, nicht nur eine Lösung, wenn möglich, weil ich versuche zu programmieren, ich bin kein Profi.
Dank
aussieht wie du sein müssen authentifiziert vor dem Download der PDF –
Was ist der Wert von 'Zielverzeichnis + Titel'? –
Der Wert wäre etwa C: \ ... Desktop \ TestFolder \ BlahBlah.pdf –