在asp.net中使用Web应用程序从我的电脑浏览一个文件
-
27-09-2019 - |
题
我有我上传使用IIS web应用。我想用的应用程序的用户将能够选择位于他们(用户)的文件计算机并阅读其内容。
的代码是:
TextReader trs = new StreamReader(faFile.Value);
DataAccessLayer.clearFA();
string line = trs.ReadLine();
// Read all unneeded data
while (line != "** Start Data **")
{
line = trs.ReadLine();
}
line = trs.ReadLine();
while (line != null)
{
string[] words = line.Split('*');
// There is no message
if (words[4] == "")
{
DataAccessLayer.insertIntoFA(Int32.Parse(words[1]), words[3].Replace("'", ""));
}
else
{
DataAccessLayer.insertIntoFA(Int32.Parse(words[1]), words[4].Replace("'", ""));
}
line = trs.ReadLine();
}
}
当我从我的电脑运行它的工作原理。但是,当我尝试从IIS它给了我下面的错误运行它:
Could not find a part of the path 'C:\Documents and Settings\myUser\Desktop\file.txt'.
据我所知,应用斜面读取来自用户PC的文件。任何想法,我怎样才能使它工作?
谢谢!
格雷格
解决方案
这是出于安全原因 - 一个浏览器没有访问用户的文件系统
有没有办法解决这个问题,作为一个浏览器中运行的所有其他技术沙盒和有限的(再次,出于安全原因)。
您可以得到最接近的是使用<input type="file">
,让用户选择要上传的文件。
其他提示
上传文件在IE 8路径是一个完整路径。您可以从全名获取文件名。保存文件之前合并服务器路径和文件名
不隶属于 StackOverflow