0

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++)
                            {
    ..............
.......
                            }
Ateeq
  • 797
  • 2
  • 9
  • 27
  • How do you want to do that? By pressing a button a display the numbers? Or Just display it in some divs when you load your page? –  Apr 19 '14 at 16:59
  • I just need to check if some files are found on the any computer that may open the website – Ateeq Apr 19 '14 at 20:27

2 Answers2

1

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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

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)

Community
  • 1
  • 1
Abhas Tandon
  • 1,859
  • 16
  • 26