手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >asp.net(c#)下读取word文档的方法小结
asp.net(c#)下读取word文档的方法小结
摘要:第一种方法:复制代码代码如下:Response.ClearContent();Response.ClearHeaders();Respons...

第一种方法:

复制代码 代码如下:

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(c#)下读取word文档的方法小结】相关文章:

asp.net OleDbCommand 的用法

asp.net Split分割字符串的方法

asp.net发邮件的几种方法汇总

Asp.net禁用页面缓存的方法总结

asp.net下Linq To Sql注意事项小结

asp.net(c#)中取得文件物理路径

asp.net动态添加js文件调用到网页的方法

asp.net通过配置文件连接Access的方法

asp.net C#检查URL是否有效的方法

asp.net导出excel的简单方法

精品推荐
分类导航