I am using ASP.Net Webforms and C# to download a file which I stored at a physical path. (C:\Users\Public\Temp). Since I did not store the file on the server, I am using a physical location to download the file using the following code snippet from the .aspx handler
HttpRequest request = System.Web.HttpContext.Current.Request;
HttpResponse response = System.Web.HttpContext.Current.Response;
String fileName = request.QueryString["fileName"];
String storagePath = "C:/Users/Public/Temp/";
String filePath = String.Format("{0}/{1}", storagePath, fileName);
response.ClearContent();
response.Clear();
response.ContentType = "application/octet-stream";
response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
response.TransmitFile(filePath);
response.Flush();
response.End();
I got the reference from the post here. But, when I initiate the download through a button click, I get the
"Could not find part of the part C:/Users/Public/Temp/"
message on the exception. I am not sure if this is because of the folder not being on the server. Is there anything I need to add to the file path? Please help me understand where I am going wrong. Please do suggest if there is a better way of doing the downloads.
(This is a prototype I am working on which I will extend to a network location)