Fuser in the ASP.NET

xiaoxiao2021-03-06  19

Fuser in the ASP.NET

I. The server outputs the corresponding HTTP Response Headers information via the response, and the data to download files to the client, HTTP Response Headers is in the HTML file: http-equiv denotes Headers name, Content represents the value of this Headers. First, to output the MIME type of the file: Page.Response.addheader (" Content-Type "," MIME Type "); Third. Second, to output the open position and file name of the downloaded file: Page.Response.addheader (" Content-Disposition "," Attachment; FileName = " filename); Content-Disposition HTTP Response Header Allows the information indicated by the document. With this header, you can specify a document separately (instead of opening in the browser), and can also be displayed according to the user's operation. If the user wants to save the document, you can also recommend a file name for the document. This suggestion name will appear in the File Name column of the Save AS dialog. Attachment - Represents as an attachment to the client, the client will open this file separately. Inline - indicates that this file will be opened in the browser. FileName - Indicates the file name sent to the client file. IV. Prepare file data sent to the client: No matter what type of files must be transferred to the array of Byte types, then output this BYTE array with the response.binarywrite method to the client. String path = "g: //download//down.txt"; system.io.fileinfo file = new system.io.fileinfo (path); response.clear (); response.addheader ("content-disposition", " attachment; filename = " HttpUtility.UrlEncode (file.Name)); Response.AddHeader (" Content-Length ", file.Length.ToString ()); Response.ContentType =" application / octet-stream "; Response.WriteFile (File.Fullname); response.end (); -------------------------------------- -------------------------------------------------- ---------------------------------- For Chinese name solution: string filename = system.Web.httputility.urlencode (System.Text.Encoding.utf8.getbytes (FilePath));

转载请注明原文地址:https://www.9cbs.com/read-50008.html

New Post(0)