0

My question is that can I do the file handing in jQuery like in C#. Suppose I want to get all directories from the particulate path we can write the code like given below.

string foldersPath = @"C:\Filesystem\Staging\Incoming";

if (Directory.Exists(foldersPath))
{
    string[] folders = Directory.GetDirectories(foldersPath, "*", System.IO.SearchOption.AllDirectories);
}

Now I want to write down this code in jQuery.

Is it possible? If yes please provide me some demo code.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shruti Singh
  • 71
  • 1
  • 10

2 Answers2

2

No, you cannot directly access the file system via JavaScript or jQuery, but you can use a jQuery .ajax() call to call a server-side resource, such as an .aspx page, .ashx (HTTP handler), ASP.NET AJAX Page Method, .asmx web service, WCF web service; which could return to you a string[] of file information via JSON.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
1

You can't do this in client side scripting using Javascript or jQuery, which is insecure. This has to be done only in server side(secure).

Update:

If you're interested in HTML5 then take a look at this Reading files in JavaScript using the File APIs

Praveen
  • 55,303
  • 33
  • 133
  • 164