IE direct download Summary

Source: Internet
Author: User

JS effect:

--------------------------------------------------------------------------------
<A href = "#" onclick = "openfile ()"> download </a>
<Script language = "JavaScript">
Function openfile ()
{
Var a = window. open ("aaa.txt", "_ blank ","");
A.document.exe cCommand ("SaveAs ");
A. close ();
}
</Script>

--------------------------------------------------------------------------------
<Script language = "C #">
<! --
/** // <Summary>
/// Used for object download
/// </Summary>
/// <Param name = "id"> id of the object to be downloaded </param>
Private void DownLoadDocument (string id)
{
// Namespace abbreviation,
* ***. BLL. Document bll = new XTMYDocMgmt. BLL. Document ();
* ***. Model. Document model = bll. GetModel (Convert. ToInt32 (id ));

String rootPath = @ Server. MapPath ("~ ") + Model. DocPath;
FileInfo toDownload = new FileInfo (rootPath );

// File Extension
String strExt = Path. GetExtension (rootPath );

Response. Clear ();
// Response. ContentType = "application/x-zip-compressed ";
Response. Charset = "UTF-8 ";
Response. ContentEncoding = System. Text. Encoding. GetEncoding ("UTF-8 ");
// The name when the file is saved .. Handle Chinese garbled characters and spaces in names
Response. appendHeader ("Content-Disposition", "attachment; filename =" + Server. urlEncode (model. docName ). replace ("+", "% 20") + strExt );

// Response. WriteFile (rootPath );
Response. TransmitFile (rootPath );

Response. End ();
}

// -->
</Script>

--------------------------------------------------------------------------------

<Script language = "c #">
<! --
// Stream method
Response. AddHeader ("Content-Disposition", "attachment; filename=aaa.txt ");
Response. ContentType = "application/octet-stream ";
Response. Flush ();
Response. Close ();
 
// -->
</Script>

--------------------------------------------------------------------------------
<Script language = "c #">
<! --

// Method 2

Response. AddHeader ("Content-Disposition", "attachment; filename=aaa.txt ");
System. IO. StreamReader sr = new StreamReader (@ "c: \ aaa.txt", System. Text. Encoding. Default );
Response. Write (sr. ReadToEnd ());
Sr. Close ();
Response. Flush ();
Response. Close ();

// -->
</Script>

 
--------------------------------------------------------------------------------

You can also set up registration through IIS.
 

In win2003 + iis6, I created a web page that displays the downloaded txt file... The content cannot be displayed...
I have added txt/plain to mime. now I want to display text content directly on the web.

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.