It is easy to use ASP. NET to output documents of the Word, Excel, txt, htm, and other types of specified content.
Call the following method in the page_load event:
1 Private Void Puttoword ()
2 {
3 Response. Clear ();
4 Response. Buffer = True ;
5 Response. charset = " UTF-8 " ;
6
7 // The following line is very important. The attachment parameter indicates downloading as an attachment. You can change it to online.
8 // Filename=fileflow.xls specifies the name of the output file. Note that the extension is consistent with the specified file type. It can be. Doc. xls. txt. htm.
9
10 Response. appendheader ( " Content-Disposition " , " Attachment?filename=fileflow.doc " );
11 Response. contentencoding = System. Text. encoding. getencoding ( " UTF-8 " );
12 // Response. contenttype specifies the file type which can be application/MS-Excel application/MS-Word application/MS-TXT application/MS-HTML or other browsers can directly support documents.
13 Response. contenttype = " Application/MS-word " ;
14 This . Enableviewstate = False ;
15
16 }