【问题标题】:Getting error as not a valid virtual path while downloading file in C # asp.net在 C# asp.net 中下载文件时出现错误,因为不是有效的虚拟路径
【发布时间】:2018-04-23 05:43:19
【问题描述】:

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

加载特定文档失败。

在调试时我也得到错误。

“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());
    }

}

【问题讨论】:

    标签: c# asp.net download virtual-path


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多