質問

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 ?

    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({
    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. 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.

Check Read a local file using JavaScript HTML5 file api (offline website)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top