Question

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++)
                            {
    ..............
.......
                            }
Was it helpful?

Solution

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.

OTHER TIPS

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top