Tuesday, November 26, 2013

return a file, c#, asp.net

string filename = "myfile.typ";
string fileStr = "";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] bytes = encoding.GetBytes(fileStr);
//or any other way to serialize your file

Response.Clear();
Response.ContentType = "application/ics;charset=utf-8";

//the general rule is (1) google (2) application/fileType (3) if is text then text/fileType
Response.AddHeader("content-disposition", "inline;filename=" + filename);
Response.BinaryWrite(bytes);
Response.End();
Response.Flush();

No comments:

Post a Comment