Click here to Skip to main content
15,896,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
By following code i am provide download functionality but after downloading the file name is Whole directory of server root file is there any solution to change it?
C#
string strURL = Server.MapPath(@"" + "~/Utils/ApplicantFiles/" + lblID.Text + "/" + strFilename);
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();
Posted
v2
Comments
StackQ 13-Dec-12 6:52am    
u can user saveFileDialog which will give more flexibilty to user at download time.

Just do like this.
C#
string filename = "YourFileName.extension";
Response.AppendHeader("Content-Disposition","attachment; filename="+ filename  +"");

Here the FileName is YourFileName.extension.

Thanks...
 
Share this answer
 
v2
Comments
Thanks for accepting the answer @kishanthakar.
Hi,
Try this

C#
Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
        Response.WriteFile(Server.MapPath(@"" + "~/Utils/ApplicantFiles/" + lblID.Text + "/" + strFilename));
        Response.Flush();
        Response.Clear();
        
        Response.Close();
 
Share this answer
 
Comments
I guess you forgot to define and declare the variable filename.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900