asp.net(c#)下讀取word文檔的方法小結(jié)
更新時(shí)間:2011年07月11日 21:00:43 作者:
asp.net(c#)下讀取word文檔的方法小結(jié),需要的朋友可以參考下。
第一種方法:
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();
復(fù)制代碼 代碼如下:
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();
第二種方法:
復(fù)制代碼 代碼如下:
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();
第三種方法:
復(fù)制代碼 代碼如下:
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();
相關(guān)文章
調(diào)試ASP.NET2005/2008時(shí),端口不正確的解決三套方案
這篇文章主要介紹了調(diào)試ASP.NET2005/2008時(shí),端口不正確的解決三套方案,小編就特別喜歡收藏這類文章,方便以后工作學(xué)習(xí)中遇到這類問題進(jìn)行解決。2015-09-09由于擴(kuò)展配置問題而無法提供您請(qǐng)求的頁面錯(cuò)誤解決方法
這篇文章主要介紹了由于擴(kuò)展配置問題而無法提供您請(qǐng)求的頁面錯(cuò)誤解決方法,需要的朋友可以參考下2014-05-05ASP.net如何連接SQL SERVER 2012數(shù)據(jù)庫
這篇文章主要介紹了ASP.net連接SQL SERVER 2012數(shù)據(jù)庫的方法,非常不錯(cuò),在項(xiàng)目開發(fā)中經(jīng)??梢杂玫?,需要的朋友可以參考下2016-08-08ASP.Net?Core中的內(nèi)存和GC機(jī)制
這篇文章介紹了ASP.Net?Core中的內(nèi)存和GC機(jī)制,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03國(guó)產(chǎn)化之銀河麒麟安裝.netcore3.1的詳細(xì)步驟(手動(dòng)安裝)
這篇文章主要介紹了國(guó)產(chǎn)化之銀河麒麟安裝.netcore3.1的詳細(xì)步驟(手動(dòng)安裝),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03.NET中RDLC循環(huán)處理數(shù)據(jù)的應(yīng)用分析
本篇文章介紹了,.NET中RDLC循環(huán)處理數(shù)據(jù)的應(yīng)用分析。需要的朋友參考下2013-05-05Entity?Framework根據(jù)實(shí)體的EntityState狀態(tài)實(shí)現(xiàn)增刪改查
這篇文章介紹了Entity?Framework根據(jù)實(shí)體的EntityState狀態(tài)實(shí)現(xiàn)增刪改查,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03