ASP. NET Document Download and asp.net Document Download
1 public void downloadfile (string s_fileName) 2 {3 HttpContext. current. response. contentType = "application/ms-download"; 4 string s_path = HttpContext. current. server. mapPath ("~ /") + S_fileName; 5 System. IO. fileInfo file = new System. IO. fileInfo (s_path); 6 HttpContext. current. response. clear (); 7 HttpContext. current. response. addHeader ("Content-Type", "application/octet-stream"); 8 HttpContext. current. response. charset = "UTF-8"; 9 10 string filename = file. name; 11 string userAgent = HttpContext. current. request. serverVariables ["http_user_agent"]. toLower (); 12 // handle the file name garbled during firefox Storage 13 if (userAgent. indexOf ("firefox") =-1) 14 filename = HttpUtility. urlEncode (filename, System. text. encoding. UTF8); 15 16 HttpContext. current. response. addHeader ("Content-Disposition", "attachment; filename =" + filename); 17 HttpContext. current. response. addHeader ("Content-Length", file. length. toString (); 18 HttpContext. current. response. writeFile (file. fullName); 19 HttpContext. current. response. flush (); 20 HttpContext. current. response. clear (); 21 HttpContext. current. response. end (); 22}