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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-18 我要评论
想了解asp.net(c#)下读取word文档的方法小结的相关内容吗,在本文为您仔细讲解asp.net下读取word文档的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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();

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们