用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

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

时间:2015-01-29  来源:互联网  作者:佚名
第一种方法:
复制代码 代码如下:
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();
来顶一下
返回首页
返回首页
推荐资讯
ASP.NET性能优化之构建自定义文件缓存 ASP.NET性能优化之构建自定义文件缓现在,借助于.NET4.0中的OutputCacheProvider,我们可以有多
sqlserver 批量数据替换助手V1.0版发布 sqlserver 批量数据替换助手V1.0版这种方法操作繁琐,而且一般不是很懂数据库的人很难操作。于
相关文章
栏目更新
栏目热门