I am downloading files from server to client machine using below code but when the file saves it saves with full path name followed by extension(Ex:Images/24/12/green.png) but i want to store only file name(green.png) in the client machine.how can it be done
string imagePath = String.Format("~/Images/{0}/{1}", item.Value,item.Text);
try
{
System.Net.WebClient req = new System.Net.WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.AddHeader("Content-Disposition","attachment;filename=\""+ imagePath + "\"");
//byte[] data = req.DownloadData(imagePath);
//response.BinaryWrite(data);
response.TransmitFile(imagePath);
response.End();
}
catch(Exception ex)
{
}
Only use the image name instead of the whole path in the
Content-Dispositionheader:You have given the file name as the file and the server side path to it.