0

我写了一段代码来从服务器下载文件。所以当我下载它时,文件会正确下载。但是当我打开文档时,它显示错误为。

无法加载特定文档。

同样在调试时我得到错误。

“https://NVMBD1BKH150V02.IN.RIL.COM/MWSiteSurveyDoc/I-KA-ANKL-ENB-0012_C2/180.jpg”不是有效的虚拟路径。

当我在浏览器中打开 URL 时,文件已正确打开。

这是我下面的代码

protected void lnkDownload_Click(object sender, EventArgs e)
{
    try
    {
        string FulfilePath = (sender as LinkButton).CommandArgument;
        string[] filePath = FulfilePath.Split('\\');               
        string path = @"" + ConfigurationManager.AppSettings["NASSServerPath_MW_Feasibility_Download"].ToString() + "/" + filePath[7] + "/" + filePath[8];
        // Response.ContentType = ContentType;                               

        Response.ContentType = ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(path));
        Response.TransmitFile(path);
        Response.End();

    }
    catch (Exception ex)
    {
        // objCom.ErrorLog(ex.GetType().ToString(), ex.Message, "Download Files", Session["UserName"].ToString());
    }

}
4

1 回答 1

1

HttpResponse.Transmit将文件的服务器物理路径作为参数。似乎您正在尝试传递远程 URI,并且还有一个错字:http://前缀中缺少斜杠。

您要么需要提供 TransmitFile 方法的本地路径,要么将请求重定向到 URI

于 2018-04-23T07:28:45.083 回答