Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to check a folder exists or not in jquery(asp.net).
Posted
Updated 24-Sep-14 2:21am
v3
Comments
Vindhyachal_Kumar 24-Sep-14 7:10am    
You want check folder on client machine or server?
Thanks7872 24-Sep-14 7:19am    
You question makes no sense at all.
Sinisa Hajnal 24-Sep-14 7:52am    
I think he means exists not exit.

As far as I understood, you have an asp.net application using jquery. But what code do you want to access the folder properties? The c#/VB or jquery?
If you are looking for a javascript code, this should do the job:

JavaScript
var fso  = new ActiveXObject("Scripting.FileSystemObject");
var folderPath = "c:\\HERE_COMES_YOUR_FOLDER_PATH";
if (!fso.FolderExists(folderPath)) {
    alert('Folder does not exist');
    return false;
}
else {
    alert('Folder exists');
    return true;
}
 
Share this answer
 
Comments
This will only work in IE, that to not sure. :)
Lisa Shiphrah 24-Sep-14 8:31am    
You can do some workarounds in order to do this code works in other browsers (like ietab for chrome). But since nobody specified a browser, this answer might be valid to him.
Richard Deeming 24-Sep-14 9:08am    
Not only will this only work in IE (or IE hosted in a frame, as with the ietab plugin), but it will only work on a Windows computer, and only if the user has changed their security settings to allow scripting of ActiveX controls not marked as safe for scripting.
Member 11106676 24-Sep-14 10:52am    
ActiveXObject not work firefox!! i try your code, this is not work!!!
Lisa Shiphrah 25-Sep-14 7:29am    
Hi genius. I've never said it would work in Firefox. The user who is asking didn't said also that he needed a solution working in Firefox. Read the question bro.
Create a Jquery ajax function that calling one service method. That method will return bool value after checking the folder exist or not. Send the folder name as ajax data

C# code
C#
public bool CheckFolder(string folderName)
        {
            string path = Request.PhysicalApplicationPath  + folderName;
            if (System.IO.File.Exists(path))
            {
                return true;
            }

            return false;
        }


After ajax success you can check the data..Using that you can know the folder exist or not.
 
Share this answer
 
v4
Comments
Can you try this and let me know, if it works or not?
[no name] 24-Sep-14 8:23am    
I guess this needs an ajax call to the server, but I think the question needs the checkto be done itself in the js file!!
Shemeemsha (ഷെമീംഷ) 24-Sep-14 8:27am    
I think he needs to check a folder in server side.. Client side folder checking is not possible..
Member 11106676 24-Sep-14 10:56am    
thanks repply, how to jquery ajax function that calling one service method?? and how to check the data to know the folder exit or not after ajax sucess? can you give example? thank you!!!
Shemeemsha (ഷെമീംഷ) 25-Sep-14 1:27am    
Are you trying to check to server side folder or client side folder..
If you are meaning to say, whether you can check if the file exists in client's machine using JavaScript/jQuery, then the answer is NO !!!

You cannot do this, because browsers won't allow you to do so, due to security restrictions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900