How to prompt ‘Save as’ for a known MIME type in C#
Posted by admin on September 8th, 2008 filed in C#Thanks to Ratheesh PK – Technical Lead – Sakhatech Information Systems Pvt Ltd,
Code snippet in ASP.NET/C# to prompt browser ‘Save as’ for known MIME types.
Response.Clear();
Response.ContentType = “application/x-unknown”;
string fileName = “file.jpg”;
string filePath = “d:\\” + fileName;
Response.AddHeader(“Content-Disposition”,”attachment; filename=” + fileName );
FileStream fs = File.OpenRead(filePath);
BinaryReader br = new BinaryReader(fs);
Response.BinaryWrite(br.ReadBytes(Convert.ToInt32(fs.Length)));
Response.End();
Leave a Comment