Asp.Net Download File With Dialog box and Name

To Download File With ForceDully Dialog Box and its name

Write Following Code

string imgPath = imgDrawing.ImageUrl;
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(imgPath));
if (file.Exists)
{
string path = imgDrawing.ImageUrl;
string name = Path.GetFileName(path);
Response.ContentType = “image/jpeg”;
Response.AppendHeader(“content-disposition”, “attachment; filename=” + name);
Response.TransmitFile(Server.MapPath(path));
Response.End();
}
else
{
lblError.Text = “File Does Not Exits.”;
}

Here Depending upon File Type  Change Response.ContentType

For Html
Response.ContentType = “text/HTML”;

For Word File
Response.ContentType = “Application/msword”;

For Pdf File
Response.ContentType = “Application/pdf”;

Advertisement