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.