简体   繁体   English

在客户端检查文件

[英]checking files on client side

I'm developing a web site on ASP.Net/MVC 4 I write this code to check the files if they are exist, but I think it will work only on the server side , how can I do the same process on the client side ? 我正在ASP.Net/MVC 4上开发一个网站。我编写此代码来检查文件是否存在,但是我认为它只能在服务器端工作,如何在客户端执行相同的过程?

    string path="c:\\Program Files";
    string[] filesName = Directory.GetDirectories(Path);
    for (int i = 0; i < filesName.Length; i++)
                            {
    ..............
.......
                            }

You cannot. 你不能。

It would be a horrible security threat if any website a user visited could explore their hard disk to see what files it had on it. 如果用户访问的任何网站都可以浏览其硬盘以查看其上包含哪些文件,这将是一个可怕的安全威胁。

That would reveal information about what software they used and whatever private information appeared in file names. 这将揭示有关他们使用什么软件以及文件名中出现的任何私人信息的信息。

You can use AJAX & jquery to check if a file exists at particular path on your server. 您可以使用AJAX和jquery检查文件是否在服务器上的特定路径中。

$.ajax({
    url:'http://www.example.com/somefile.ext',
    type:'HEAD',
    error: function()
    {
        //file not exists
    },
    success: function()
    {
        //file exists
    }
});

Due to security reasons javascript can't directly access clients's file system. 出于安全原因,javascript无法直接访问客户端的文件系统。 Maximum that yo can do is that you may have a browse button that allows user to browse and point to the file and then you can validate the file and perform the desired action. 您所能做的最大事情就是您可能具有一个浏览按钮,该按钮允许用户浏览并指向文件,然后您可以验证文件并执行所需的操作。 Otherwise try using java applets/flash. 否则,请尝试使用Java Applet / Flash。

Check Read a local file using JavaScript HTML5 file api (offline website) 选中使用JavaScript HTML5文件api读取本地文件(离线网站)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM