0

我有一个使用 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 读取文件。知道如何使它工作吗?

谢谢!

格雷格

4

2 回答 2

0

这样做是出于安全原因 - 浏览器无权访问用户的文件系统。

没有办法解决这个问题,因为在浏览器中运行的所有其他技术都是沙盒和受限的(同样,出于安全原因)。

您可以获得的最接近的方法是使用<input type="file">允许用户选择要上传的文件。

于 2010-08-11T12:32:58.287 回答
0

IE 8 中上传文件的路径是完整路径。您可以从全名中获取文件名。在保存文件之前结合服务器路径和文件名

于 2013-11-01T05:32:45.217 回答