程序实现下载文件或者打开文件

时间:2022-04-23
本文章向大家介绍程序实现下载文件或者打开文件,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
FileInfo DownloadFile = new FileInfo("c:\a.doc");  
// 下面到就是读取文件,通过数据流的方式下载了。  
Response.Clear();  
Response.ClearHeaders();  
Response.Buffer = false;  
Response.ContentType = "application/octet-stream";  
Response.AppendHeader("Content-Disposition", "inline;filename=" + HttpUtility.UrlEncode("c:\a.doc", System.Text.Encoding.UTF8));  
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());  
Response.WriteFile(DownloadFile.FullName);  
Response.Flush();  
Response.End(); 

Content-Disposition:inline是直接打开,attachment是保存。