C#如何使用WebClient解决问题? [英] C# how to solve the problem using webclient?
本文介绍了C#如何使用WebClient解决问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
C#webclient,如何解决下载文件名中包含\/:*的问题? & lt;& gt;这个符号?
最好的问候.
Dear,
C# webclient, how to solve the problem about the download file name contain \ / : * ? " < > this symbols?
Best Regards.
推荐答案
在定义文件名时尝试使用@或\转义序列.
Try using @ or \ escape sequences when you are defining the file name.
文件名很难可以包含:","*"或?".从客户端的角度来看,这不是文件而是URL,因此目录定界符为"/"(但是,如果URL是本地文件,则也接受"\").这怎么可能是个问题?
Abhinav正确地解释了您可以将任何这些字符放入字符串文字中.这是一个问题吗?如果是这样,请记住,实际上在任何情况下都不应在代码中使用硬编码的字符串常量,尤其是这是一个URL.
-SA
A file name hardly can contain ":", "*" or "?". From the client standpoint, this is not a file but URL, so the directory delimiter is "/" (however "\" is also accepted if the URL is a local file). How can this be a problem?
Abhinav correctly explained that you can put any of these characters in a string literal. Is this was a problem? If it was, remember that there is practically no situation when you should use hard-coded string constants in your code, especially it this is a URL.
—SA
签出 ^ ].
使用EscapeUriString方法准备一个未转义的URI字符串作为Uri构造函数的参数.
Check out Uri.EscapeUriString[^].
Use the EscapeUriString method to prepare an unescaped URI string to be a parameter to the Uri constructor.
这篇关于C#如何使用WebClient解决问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文