Asp.net response. addheader method to download

Source: Internet
Author: User

System. Io. fileinfo info = new system. Io. fileinfo (server. mappath ("data \") + "filename.exe ");

Protected void button3_click (Object sender, eventargs E)
{
Response. Clear ();
Response. clearheaders ();
Response. Buffer = true;

// Specify a stream that cannot be read by the client and must be downloaded.
Response. contenttype = "application/octet-stream ";

// Add the header information and specify the default file name for the "download/Save as" dialog box
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (info. Name, system. Text. encoding. utf8 ));

// Add header information and specify the file size so that the browser can display the download progress.
Response. addheader ("Content-Length", info. length. tostring ());
// Response. addheader ("content-transfer-encoding", "binary ");

// Specify a stream that cannot be read by the client and must be downloaded.
// Response. addheader ("Content-Type", "application/X-msdownload ");

// Specify a stream that cannot be read by the client and must be downloaded.
// Response. contenttype = "application/MS-excel ";

// Send the file stream to the client
Response. writefile (info. fullname );
Response. Flush ();
Response. End ();
}

File Download, specifying the default name
Response. addheader ("Content-Type", "application/X-msdownload ");
Response. addheader ("content-disposition", "attachment?filename=file name to be downloaded. rar ");

Refresh page
Response. addheader "refresh", "60; url = newpath/Newpage. asp"
This is equivalent to the client <meta> element:
<Meta HTTP-EQUIV = "refresh", "60; url = newpath/Newpage. asp"

Page Orientation
Response. Status = "302 Object Moved"
Response. addheader "location", "newpath/Newpage. asp"
This is equivalent to using the response. Redirect method:
Response. Redirect "newpath/Newpage. asp"

Force the browser to display a user name/Password dialog box
Response. Status = "401 unauthorized"
Response. addheader "www-authenticate", "basic"
Force the browser to display a user name/Password dialog box, and then send them back to the server using basic verification (the verification method will be seen later in this book ).

How to Make webpages unbuffered
Response. expires = 0
Response. expiresabsolute = now ()-1
Response. addheader "Pragma", "No-Cache"
Response. addheader "cache-control", "private"
Response. cachecontrol = "no-Cache"

From: http://hi.baidu.com/jackeyrain/blog/item/afcdc633eeb8b6ff1b4cffd6.html

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.