asp.net 讀取word 文檔的方法

jopen 14年前發布 | 1K 次閱讀

//第一種方法:
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();</pre>

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!