Asp.net generates TXT text files

Source: Internet
Author: User

 Asp.net is used to automatically generate a TXT text file based on the data content and provide users with download. This method is not saved on the server and is directly provided to users for download, 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

Http://www.the9web.com/blog/2009/09/07/175/
From: http://qingtiansunsky.blog.163.com/blog/static/95006479201023004134905/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.