asp.net dynamically generate TXT file and provide user download code __.net

Source: Internet
Author: User

The following to achieve this function is to use asp.net based on the data content to automatically generate a TXT text file and provide users to download, this method file does not exist on the server, directly provided to the user to download, to the online search, are used Response.BinaryWrite (), with a few, Found that there is a problem in IE, look at the page source code data is out, Firefox is a pop-up box to download, but not txt, but ASPX, inside the content is taken out of the database from the data.

In fact, in asp.net directly with write () on it, the code is as 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 database, loop
for (i=0;i<100;i++)
{
Response.Write ("1234| abcde/r/n ");
}
Response.Flush ();
Response.End ();

In IE and Firefox debugging through


This article is from: it knows Net (http://www.itwis.com) detailed source reference: http://www.itwis.com/html/net/aspnet/20081016/2599.html

Related Article

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.