In order to download an image click on a href link follow below steps:
Step1: Create a ASHX generic file to download an image.
public class DownloadFile : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string destPath = context.Server.MapPath(HttpContext.Current.QueryString["path"]);
FileInfo fi = new FileInfo(destPath);
if (fi.Exists)
{
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AppendHeader("Content-Length", fi.Length.ToString());
HttpContext.Current.Response.ContentType = "application/image";;
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=temp.png");
HttpContext.Current.Response.WriteFile(destPath);
HttpContext.Current.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Step2: Now change in code behind where you are adding href link
foreach (var item in attachments)
{
strAttchments.Append("<a style=\"color: blue\" href ='DownloadFile.ashx?path=" + item.URL + "' >" + item.Name + "</ a > <br />");
}
Link should look like:
<a style="color: blue" href="DownloadFile.ashx?path=E:/Documents/Marketing/1/ComboxCommnets.png">Download</a>