检索文件从IIS服务器将使用特殊字符名称C#.NET
问题描述:
我有位于http://10.1.10.211:8600/CardsPro+.exe检索文件从IIS服务器将使用特殊字符名称C#.NET
一个文件,我想用下面的代码检索它,但得到的错误 “HTTP错误404.11 - 未找到“
private WebClient webClient;
private BackgroundWorker bgWorker;
private string tempFile;
private string md5;
internal string TempFilePath
{
get { return this.tempFile; }
}
internal UpdateInfoDownloadForm(Uri location, string md5, Icon programIcon)
{
InitializeComponent();
if (programIcon != null)
{
this.Icon = programIcon;
}
tempFile = Path.GetTempFileName();
this.md5 = md5;
webClient = new WebClient();
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
bgWorker = new BackgroundWorker();
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BgWorker_RunWorkerCompleted);
try
{
string strend = location.ToString().Substring(location.ToString().LastIndexOf('/')+1);
string strstart = location.ToString().Substring(0,location.ToString().LastIndexOf('/')+1);
strend = System.Web.HttpUtility.UrlEncode(strend);
Uri locn = new Uri(strstart+strend);
webClient.DownloadFileAsync(locn, this.tempFile); **//It fails here**
}
catch(Exception ex)
{ this.DialogResult = DialogResult.No; this.Close(); }
}
我如何通过URI来获得具有特殊字符在它的名称的文件?
当我更改文件名时它起作用。
答
对于包含特殊字符的文件地址,您要下载的文件取决于服务器支持特殊字符访问的部署。
例如,如果IIS服务器不支持使用特殊字符访问,那么使用url进行了哪些更改,结果是不可能的。
以下是有关处理文件名包含特殊字符的解决方案,您可以参考它。