【发布时间】:2015-01-22 09:40:33
【问题描述】:
我希望能够从我的 ASP.NET WebApp 中的特定文件夹上传/下载文件, 现在由于应用程序驻留在 C:/ 目录中,我不想占用该分区中的空间,所以我添加了一个指向文件夹 E:/Docs/Emps/ 的虚拟目录 现在我可以正常上传了.. 但我在 E:/Docs/Emps/ 中找不到文件,它不存在, 当我搜索它们时,结果带有我在 IIS 中创建的虚拟文件夹中的 URL, 现在当我开始实现下载部分时..我根本无法下载它, 我找不到/访问[如果我设法找到它们]文件 在 Google 上呆了太多时间后,我尝试使用 WebClient,但我遇到了这个异常
消息
------------
在 WebClient 请求期间发生异常。
-----------
内部异常
-----------
System.NotSupportedException:不支持给定路径的格式。在 System.IO.FileStream.Init(字符串路径、FileMode 模式、FileAccess 访问、Int32 权限、Boolean useRights、FileShare 共享、Int32 bufferSize、FileOptions 选项、SECURITY_ATTRIBUTES secAttrs、String msgPath、Boolean bFromProxy、Boolean useLongPath、Boolean checkHost)在 System System.Net.WebClient.DownloadFile(Uri address, String fileName) 的 .IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
-----------
堆栈跟踪
------------
在 System.Net.WebClient.DownloadFile(Uri address, String fileName) at System.Net.WebClient.DownloadFile(String address, String fileName) at APC_ERP.BusinessCore_EmployeesDocumentsCenter.imgbtnDownloadDocument_Click(Object sender, ImageClickEventArgs e)
这是我正在使用的下载代码
WebClient Client = new WebClient();
string Path = Server.MapPath("~/"+(sender as ImageButton).CommandArgument);
string[]File=Path.Split('/');
string Destination = @"C:\" + File[File.Length - 1];
Client.DownloadFile(Path, Destination);
Client.Dispose();
【问题讨论】: