加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 05:42:03 所属栏目:百科 来源:网络整理
导读:第一种方法: 复制代码 代码如下: Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "Application/msword"; string s=Server.MapPath("C#语言参考.doc"); Response.WriteFile("C#语言参考.doc"); Response.Write(s); Response.Flu
第一种方法:
复制代码 代码如下:

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,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,(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();

您可能感兴趣的文章:

  • C#对Word文档的创建、插入表格、设置样式等操作实例
  • C#设置Word文档背景的三种方法(纯色/渐变/图片背景)
  • C# 向Word中设置/更改文本方向的方法(两种)
  • C#添加、读取Word脚注尾注的方法
  • C# WORD操作实现代码
  • C#实现通过模板自动创建Word文档的方法
  • C# Word 类库的深入理解
  • 比较全的一个C#操作word文档示例
  • C# 利用Aspose.Words.dll将 Word 转成PDF
  • C#如何更改Word的语言设置

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读