源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

asp.net(c#)下读取word文档的方法小结

  • 时间:2022-06-30 23:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:asp.net(c#)下读取word文档的方法小结
第一种方法:
[u]复制代码[/u] 代码如下:
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();
第二种方法:
[u]复制代码[/u] 代码如下:
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();
第三种方法:
[u]复制代码[/u] 代码如下:
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();
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部