使用javascript调用共享驱动器文件夹

Calling shared drive folder using javascript

本文关键字:驱动器 文件夹 共享 调用 javascript 使用      更新时间:2023-09-26

我有两个服务器:A和B。我的经典ASP应用程序部署在服务器A上。服务器B包含一个文件夹(ScannedDocuments(。我已经在服务器a上创建了一个共享驱动器来指向此文件夹。共享驱动器名为Q:。

在IE 7上,当我尝试使用javascript访问文件时,我使用的是:

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

它打开文件。但在IE 8及以上版本和所有版本的Firefox上,它都不会打开。既没有生成错误,也没有打开文件。

我猜它被浏览器的安全功能阻止了。

请告诉我如何在这些浏览器版本上打开文件。

有没有其他方法可以使用javascript或IIS打开远程文件?

**已编辑**我尝试在IIS上创建虚拟目录并指向共享驱动器。但它给出了一个错误:找不到资源或目录。

我正在使用IIS 7

@Anant Dabhi是对的-创建一个简单的Ajax调用来服务器ant返回文件内容。

客户端(JS(。使用它而不是window.open(文件://Q:/a.txt(

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

你的"后台"。假设您正在使用.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 });
}

如果愿意,可以连接到UNChttps://msdn.microsoft.com/en-us/library/windows/desktop/aa385482%28v=vs.85%29.aspx