Kash
Kash

Reputation: 341

How to access a shared/network folder using JavaScript?

I have a requirement to develop a tool to backup certain folders and files present in a shared drive (Windows 7) using Client-Side technologies (HTML5, CSS3 and JavaScript) only. Below is the JavaScript function to copy the file.

function copyFile() {
    var myObject, f;
    myObject = new ActiveXObject("Scripting.FileSystemObject");
    f = myObject.GetFile("@\\Network_Name\Home$\User_Folder\Downloads\Folder_Name\Test.pdf");
    if(!f)
    {
        return alert("File Not Found");
    }
    f.copy("@\\Network_Name\Home$\User_Folder\Downloads\Backup_Folder");
}

Since I'm using ActiveXObject, the above code will work only in IE. But I'm getting the below error in the line @\\Network_Name\Home$\User_Folder\Downloads\Folder_Name\Test.pdf. Please help me to properly access the network folder using JavaScript.

Snapshot of Error

Upvotes: 1

Views: 10659

Answers (2)

Alex K.
Alex K.

Reputation: 175768

The verbatim identifier (@) is for C# not JavaScript, you need to escape your slashes:

.GetFile("\\\\Network_Name\\Home$\\User_Folder\\Downloads\\Folder_Name\\Test.pdf");

Upvotes: 3

Vatsal Pathak
Vatsal Pathak

Reputation: 68

Try to use Ajax request method type "GET" for this purpose.

Upvotes: 0

Related Questions