The following function is to use Asp.net to automatically generate a TXT text file based on the data content and provide users with download. This method does not save the file on the server and is directly provided to users for download, I searched the internet and used response. binarywrite (), used a few times, found that there is a problem in IE, look at the pageSource codeThe data is generated. In Firefox, a box is displayed to download the data, but not txt, but Aspx. The content in the box is the data obtained from the database.
In fact, you can simply use write () in ASP. NET,CodeAs follows (. aspx. CS file ):
Response. Clear ();
Response. Buffer = false;
Response. contenttype = "application/octet-stream ";
Response. appendheader ("content-disposition", "attachment; filename =" + filename + ". txt ;");
Response. Write ("1234 | ABCDE/R/N ");
// Read the database, loop
For (I = 0; I <100; I ++)
{
Response. Write ("1234 | ABCDE/R/N ");
}
Response. Flush ();
Response. End ();
Both IE and Firefox
This article from: It Knowledge Network (http://www.itwis.com) detailed source reference: http://www.itwis.com/html/net/aspnet/20081016/2599.html