MVC C # Direct Export TXT file

Source: Internet
Author: User

With ASP. Automatically generate a txt text file according to the data content and provide user download, this method file does not protect the existence of the server, directly to the user to download, to search the Internet, are used Response.BinaryWrite (), with a few, found that there are problems 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 extracted from the database data.

In fact, you can use write () directly in ASP. The code is as follows (MVC 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 ();

return new Emptyresult ();

Through IE and Firefox debugging

MVC C # Direct Export TXT file

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.