[英]Accessing File by File Upload
I developed an application. 我开发了一个应用程序。 In that I am uploading a file by file upload. 我在逐个文件上传一个文件。 Now I want to access the file which is uploaded. 现在,我要访问上传的文件。 Right now I am accessing the file by giving name. 现在,我正在通过提供名称来访问文件。
Below is my code: 下面是我的代码:
if(PostedFile !=null && PostedFile.ContentLength>0 )
{
MyFile = Path.GetFileName(PostedFile.FileName);
PostedFile.SaveAs(Server.MapPath(Path.Combine("~/UploadedFile/", MyFile)));
StreamReader reader = new StreamReader(Server.MapPath("~/UploadedFile/aab.html"));
}
I want to access the file which is saved in the UploadedFile folder by the use of StreamReader. 我想使用StreamReader访问保存在UploadedFile文件夹中的文件。 Right now I am giving the same file which is selected by me in file upload. 现在,我要提供与我在文件上传中选择的文件相同的文件。
I have also tried this code: 我也尝试过此代码:
if(PostedFile !=null && PostedFile.ContentLength>0 )
{
MyFile = Path.GetFileName(PostedFile.FileName);
PostedFile.SaveAs(Server.MapPath(Path.Combine("~/UploadedFile/", MyFile)));
StreamReader reader = new StreamReader(MyFile));
}
But the debugger shows the error in stream reader line: 但是调试器在流读取器行中显示错误:
Could not find file 'C:\Program Files (x86)\IIS Express\aab.html'.
I solved my question. 我解决了我的问题。
Here is my updated code: 这是我更新的代码:
StreamReader reader = new StreamReader(Server.MapPath(PostedFile.FileName));
Thanks to all. 谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.