简体   繁体   中英

Calling shared drive folder using javascript

I have two servers: A and B. My Classic ASP application is deployed on Server A. Server B contains a Folder (ScannedDocuments). I have created a Shared Drive on Server A to point to this folder. The Share Drive is named Q:.

On IE 7, when I try to access file using javascript, I am using:

window.open(file://Q:/a.txt)

It opens the file. But on IE 8 and above and all versions of Firefox, it is not opening. Neither an error is generated nor the file is opening.

I guess it is getting blocked by browser's security features.

Please let me know how I can open files on these browser versions.

Is there any other way to open a remote file using javascript or using IIS?

** Edited ** I tried creating a Virtual Directory on IIS and pointing to Shared Drive. But it gives error: resource or directory not found.

I am using IIS 7

@Anant Dabhi is right - create simple Ajax call to server ant return file content.

Client (JS). Use it instead of window.open(file://Q:/a.txt)

function getFile(filename) {
    $.ajax({
        url: "/YourWeb/File/Get",
        data: {
            filename: filename
        },
        success: function (data) {
            console.log(data);
        }
    });
}

Your "backend". Assume that your are using .NET :)

public ActionResult Get()
{
    string pathToFolder = "x:\\yyy\\zzz";
    // Strip any directories and leave only name of file. Exception is possible ;)
    string filename = Path.GetFileName(Request["filename"]);
    byte[] ba = File.ReadAllBytes(Path.Combine(pathToFolder, filename));
    string s = Encoding.UTF8.GetString(ba);

    // Return as text (if you are absolutetlly sure it is text!)
    return Content(s);
    // Or pack it in JSON object to have status
    return Json(new { Status = true, Data = s });
}

You could connect to UNC if you wish https://msdn.microsoft.com/en-us/library/windows/desktop/aa385482%28v=vs.85%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM