0

I have written a piece of code for downloading the file from the server. So when I download it, the file gets downloaded properly. But when I Open the document, it shows me error as.

Failed to load particular document.

Also while debugging I get error as.

'https:/NVMBD1BKH150V02.IN.RIL.COM/MWSiteSurveyDoc/I-KA-ANKL-ENB-0012_C2/180.jpg' is not a valid virtual path.

when I open the URL in browser, the file is opened properly.

Here is my code below

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

}
dtlvd
  • 457
  • 1
  • 8
  • 21
Nad
  • 4,605
  • 11
  • 71
  • 160

1 Answers1

1

HttpResponse.Transmit takes a server physical path to a file as a parameter. Seems you are trying to pass a remote URI instead, and there is also a typo: a slash is missing in http:// prefix.

You either need to provide a local path to the TransmitFile method or redirect the request to the URI

Nerlog
  • 261
  • 1
  • 5