如何从Web服务器C#Web应用程序获取本地计算机文件路径

问题描述:

我正在开发一个Web应用程序,我想在其中列出本地计算机上的文件,例如d:\ Trial Folder

实际上,所有将要使用我的Web应用程序的用户都将在其本地驱动器"D:\"冒号上拥有Trial文件夹,即每个用户都将拥有d:\ Trial文件夹

现在,当用户登录时,我想向他显示d:\ Trial文件夹中的所有文件列表.

但我不知道如何获取本地机器路径

我使用了System.IO的代理,但是我没有得到下面的文件,这是我的示例代码

请帮帮我

i am developing a web application in which i want to list out the files on local computers lets say d:\Trial Folder

actually all the user who is going to use my web application will have Trial folder on their local drive "D:\" colon i.e. each user will have d:\Trial Folder

now when user login then i want to show him the all file list from d:\Trial folder to him.

but i dont know how to get the local machine path

i used System.IO''s deiectory but i am not getting the file below is my sample code

please help me out

string dipath=@"d:\\Trial\\";
string[] dirs = Directory.GetFiles(dipath);
foreach (string dir in dirs)
{
Label1.Text = Label1.Text + dir;
}

您需要在此处了解以下几点.

首先是Directory.GetFiles在服务器端工作-这是在Web进程内部运行的.NET代码.

第二个更大的问题是,除了使用诸如ActiveX功能之类的东西之外,没有真正可靠的方法可以从网页访问客户端文件系统-而且也不应该存在;如果存在,这将是一个主要的安全漏洞,因为这意味着任何站点都可以访问您系统上的文件.

最后一个想法,供您思考.如果从iPad或Unix盒子等网站查看您的网站会怎样?
There are a couple of things you need to understand here.

The first is that Directory.GetFiles works on the server side - this is .NET code that runs inside the web process.

The second, much bigger issue, is that apart from using things like ActiveX functionality, there is no real reliable way to get access to the client file system from a web page - and nor should there be; if there were, this would be a major security hole because it would mean that any site could get access to the files on your system.

A last thought, for you to ponder. What happens if your site is viewed from something like an iPad, or a Unix box?