Issue
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
I found out the answer after searching in Internet. The code is.
WebClient req=new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer= true;
response.AddHeader("Content-Disposition","attachment;filename=\"" +strURL + "\"");
byte[] data=req.DownloadData(strURL);
response.BinaryWrite(data);
response.End();
Answered By – Anand Raj
Answer Checked By – Candace Johnson (BugsFixing Volunteer)