Download a file directly

xiaoxiao2021-03-06  56

It is a content management system that is resolutely not allowed to put documents or programs in a directory that cannot be accessed in an IIS due to permissions. Therefore, it is necessary to use the ASP.NET to read the contents of the file to write to the browser. Look at the uESTC95 [.NET TIPS 1001] ASP.NET downloads a file directly, not in IE, it is inspired. But lazy nature is what I think this method is a bit trouble. Fortunately, this method of finding response.writefile can minimize the workload of comrades. ,code show as below

Response.clear ()

Response.contentType = "Application / OcTet-stream"

Response.addheader ("Content-Disposition", "Attachment; FileName =" httputility.urlencode (filename, system.text.encoding.utf8))

Response.writefile (FilePath Filname)

Response.end ()

Of course, everyone can add some of the privileges that judge it here.

Http://support.microsoft.com/default.aspx?scid=kb;n-us; 317719how to export data in a DataGrid on an ASP. NET Webform to Microsoft Excel

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

New Post(0)