asp.net(c#)下讀取word文檔的方法小結
更新時間:2011年07月11日 21:00:43 作者:
asp.net(c#)下讀取word文檔的方法小結,需要的朋友可以參考下。
第一種方法:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string s=Server.MapPath("C#語言參考.doc");
Response.WriteFile("C#語言參考.doc");
Response.Write(s);
Response.Flush();
Response.Close();
第二種方法:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string strFilePath="";
strFilePath =Server.MapPath("C#語言參考.doc");
FileStream fs = new FileStream(strFilePath,FileMode.OpenOrCreate,FileAccess.Read);
Response.WriteFile(strFilePath,0,fs.Length);
fs.Close();
第三種方法:
string path=Server.MapPath("C#語言參考.doc");
FileInfo file=new FileInfo(path);
FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read);
byte[] filedata=new Byte[file.Length];
myfileStream.Read(filedata,0,(int)(file.Length));
myfileStream.Close();
Response.Clear();
Response.ContentType="application/msword";
Response.AddHeader("Content-Disposition","attachment;filename=文件名.doc");
Response.Flush();
Response.BinaryWrite(filedata);
Response.End();
復制代碼 代碼如下:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string s=Server.MapPath("C#語言參考.doc");
Response.WriteFile("C#語言參考.doc");
Response.Write(s);
Response.Flush();
Response.Close();
第二種方法:
復制代碼 代碼如下:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string strFilePath="";
strFilePath =Server.MapPath("C#語言參考.doc");
FileStream fs = new FileStream(strFilePath,FileMode.OpenOrCreate,FileAccess.Read);
Response.WriteFile(strFilePath,0,fs.Length);
fs.Close();
第三種方法:
復制代碼 代碼如下:
string path=Server.MapPath("C#語言參考.doc");
FileInfo file=new FileInfo(path);
FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read);
byte[] filedata=new Byte[file.Length];
myfileStream.Read(filedata,0,(int)(file.Length));
myfileStream.Close();
Response.Clear();
Response.ContentType="application/msword";
Response.AddHeader("Content-Disposition","attachment;filename=文件名.doc");
Response.Flush();
Response.BinaryWrite(filedata);
Response.End();
相關文章
調試ASP.NET2005/2008時,端口不正確的解決三套方案
這篇文章主要介紹了調試ASP.NET2005/2008時,端口不正確的解決三套方案,小編就特別喜歡收藏這類文章,方便以后工作學習中遇到這類問題進行解決。2015-09-09國產化之銀河麒麟安裝.netcore3.1的詳細步驟(手動安裝)
這篇文章主要介紹了國產化之銀河麒麟安裝.netcore3.1的詳細步驟(手動安裝),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03Entity?Framework根據實體的EntityState狀態(tài)實現增刪改查
這篇文章介紹了Entity?Framework根據實體的EntityState狀態(tài)實現增刪改查,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03