下载包含无效字符的URL文件 [英] Download URL file with invalid characters
问题描述
我在c#windows窗体应用程序中使用以下代码来下载URL文件。
System.Net.WebClient webClient = new System。 Net.WebClient();
webClient.DownloadString(sourceFile);
//开始下载并复制文件
webClient.DownloadFileAsync(new Uri(sourceFile),destinationFilePath);
但是当我使用时这样的网址无法下载。任何错误也不会到来。其他网址文件下载得很好。
我用目的文件"c:\\ test.png"尝试了你的代码。并有同样的问题。删除DownloadFileAsync调用的Async部分可以让您检查出现了什么问题。在我的情况下,我在c:\test.png上获得了拒绝访问权限。当我尝试在其他地方保存图像
时,正常和异步调用都有效。
代码我用来检查你的代码:
< pre class ="prettyprint"> string sourceFile =" http://www.archicadwiki.com/DWG/Import/LayerVisibilityOnLayout?action = AttachFile& do = get& target = AC10-DWG.png" ;;
System.Net.WebClient webClient = new System.Net.WebClient();
webClient.DownloadString(sourceFile);
webClient.DownloadFileAsync(new Uri(sourceFile)," d:\\ test.png");
希望这有帮助
I'm using following code in my c# windows form application to download a URL file.
System.Net.WebClient webClient = new System.Net.WebClient(); webClient.DownloadString(sourceFile); // Start the download and copy the file webClient.DownloadFileAsync(new Uri(sourceFile), destinationFilePath);
But when I'm using a url like this it doesn't get downloaded. Any error also not coming. Other url files getting downloaded well.
Hi,
I tried your code with a destinationfile "c:\\test.png" and had the same issue. Removing the Async part of the DownloadFileAsync call gives you a way to check what's going wrong. In my case I got an access denied on c:\test.png. When I tried saving the image somewhere else, both the normal and the Async call worked.
Code I used to check your code:
string sourceFile = "http://www.archicadwiki.com/DWG/Import/LayerVisibilityOnLayout?action=AttachFile&do=get&target=AC10-DWG.png"; System.Net.WebClient webClient = new System.Net.WebClient(); webClient.DownloadString(sourceFile); webClient.DownloadFileAsync(new Uri(sourceFile), "d:\\test.png");
Hope this helps
这篇关于下载包含无效字符的URL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!