''http:/***.168.**.8:***/UploadedFiles/CustomerKYC/Photo/134_26581.jpg' is not a valid virtual path

I am getting the exception http:/.168.11.8:/UploadedFiles/CustomerKYC/Photo/134_26581.jpg' is not a valid virtual path when I write either WriteFile or TranferFile in the following code. Please give me a code fix.

    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AppendHeader("content-disposition", "filename=" +NavigateURLID.Value);
    Response.WriteFile(Server.MapPath(url));
    Response.Flush();
    Response.End();

I need the file from the url to be downloaded. They are all image files only(jpg)



Solution 1:[1]

Try this code will help

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

Reference url: https://www.aspsnippets.com/Articles/Upload-and-Download-files-from-Folder-Directory-in-ASPNet-using-C-and-VBNet.aspx

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mohd mazhar khan