Protected void page_load (Object sender, eventargs E)
{
This. writetodoc ("Personal Data", "application/vnd.doc", "content: My name is" quiet "");
}
Private void writetodoc (string filename, string filetype, string filetxt)
{
// Clear the content of the reversed Area
Response. Clear ();
// Set the HTTP Character Set of the output stream
Response. charset = "gb2312 ";
// Add an HTTP header to the output stream
Httpbrowsercapabilities HBC = system. Web. httpcontext. Current. Request. browser;
String browsertype = HBC. browser. tostring (). tolower ();
If (browsertype = "Firefox ")
{
Response. addheader ("content-disposition", "attachment; filename =" + filename + ". Doc ");
}
Else
{
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (encoding. utf8.getbytes (filename + ". Doc ")));
}
// Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (filename, system. Text. encoding. utf8) + ". Doc ");
// Set the output http mime type
Response. contenttype = filetype;
System. Text. stringbuilder sb = new system. Text. stringbuilder ();
SB. append (filetxt );
// Write the character array to the HTTP Response output stream
Response. Write (sb. tostring ());
// Close after sending
Response. End ();
}