[英]Upload / Download From Virtual Directories in ASP.NET C#
i want to be able to upload / Download Files from a specific folder in my ASP.NET WebApp, now since the app resides in the C:/ directory i didn't want to occupy the space in that partition, so i added a virtual directory pointing to the folder E:/Docs/Emps/ now i can upload fine .. but i can't find the the files in E:/Docs/Emps/ it's not there , and when i search for them the results come with a URL inside the virtual folder i created in IIS , now when i started to implement the download part .. i couldn't download it at all , i can't find / access[if i managed to find them] the files after too much time on Google, i tried to use WebClient but i'm getting this exception 我希望能够从ASP.NET WebApp中的特定文件夹上载/下载文件,现在由于该应用程序位于C:/目录中,所以我不想占用该分区中的空间,因此我添加了一个虚拟指向文件夹E:/ Docs / Emps /的目录,现在我可以上传了..但我找不到E:/ Docs / Emps /中的文件,它不存在,当我搜索它们时,结果随我在IIS中创建的虚拟文件夹中的URL,现在当我开始实现下载部分时..我根本无法下载它,也无法找到/访问[如果我设法找到它们]文件在Google上花了很多时间,我尝试使用WebClient,但出现此异常
Message
信息
----------------------
An exception occurred during a WebClient request.WebClient请求期间发生异常。
----------------------
Inner Exception内部异常
----------------------
System.NotSupportedException: The given path's format is not supported.System.NotSupportedException:不支持给定路径的格式。 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) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at System.Net.WebClient.DownloadFile(Uri address, String fileName)
在System.IO.FileStream.Init(系统上的字符串路径,FileMode模式,FileAccess访问,Int32权限,布尔useRights,FileShare共享,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,字符串msgPath,布尔bFromProxy,布尔useLongPath,布尔checkHost)处.IO.FileStream..ctor(字符串路径,FileMode模式,FileAccess访问),位于System.Net.WebClient.DownloadFile(Uri地址,字符串fileName)
----------------------
Stack Trace堆栈跟踪
----------------------
at 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)在System.Net.WebClient.DownloadFile(Uri地址,字符串fileName)在System.Net.WebClient.DownloadFile(字符串地址,字符串fileName)在APC_ERP.BusinessCore_EmployeesDocumentsCenter.imgbtnDownloadDocument_Click(对象发送者,ImageClickEventArgs e)
here's the download code i'm using 这是我正在使用的下载代码
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();
The content of your variable Path
seems incorrect. 您的变量
Path
的内容似乎不正确。 First of all a forward slash is not supported, secondly the tilde (~) might be an issue - I'm not sure about the latter one though. 首先不支持正斜杠,其次也许是代字号(〜)-我不确定后者。 As we can't see your data you should debug and check this path variable as well as
Destination
. 由于我们看不到您的数据,因此您应该调试并检查此路径变量以及
Destination
。
Also, instead of using +
it's recommended to use the static Combine
method for path-related operations. 另外,建议不要使用
+
,而将static Combine
方法用于与路径相关的操作。 Example: 例:
Path.Combine(@"\\root\", (sender as ImageButton).CommandArgument);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.