asp.net 读取word 文档的方法新随笔 1. net 学习线路图,csdn真给力啊!

简介: 第一种方法:    Response.ClearContent();   Response.ClearHeaders();   Response.ContentType = "Application/msword";   string s=Server.

第一种方法:
   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(); 

http://www.cnblogs.com/suneryong/archive/2007/06/05/772115.html

目录
相关文章
|
5月前
|
Linux C# Windows
.NET使用MiniWord高效生成Word文件
.NET使用MiniWord高效生成Word文件
148 12
|
9月前
|
SQL 缓存 开发框架
分享一个 .NET EF6 应用二级缓存提高性能的方法
分享一个 .NET EF6 应用二级缓存提高性能的方法
|
8月前
|
开发框架 前端开发 .NET
VB.NET中如何利用ASP.NET进行Web开发
在VB.NET中利用ASP.NET进行Web开发是一个常见的做法,特别是在需要构建动态、交互式Web应用程序时。ASP.NET是一个由微软开发的开源Web应用程序框架,它允许开发者使用多种编程语言(包括VB.NET)来创建Web应用程序。
194 6
|
9月前
|
开发框架 JSON .NET
ASP.NET Core 标识(Identity)框架系列(三):在 ASP.NET Core Web API 项目中使用标识(Identity)框架进行身份验证
ASP.NET Core 标识(Identity)框架系列(三):在 ASP.NET Core Web API 项目中使用标识(Identity)框架进行身份验证
122 1
|
10月前
|
开发框架 搜索推荐 前端开发
【.NET全栈】ASP.NET开发Web应用——Web部件技术
【.NET全栈】ASP.NET开发Web应用——Web部件技术
|
9月前
|
开发框架 .NET 开发工具
【Azure 应用服务】App Service 的.NET Version选择为.NET6,是否可以同时支持运行ASP.NET V4.8的应用呢?
【Azure 应用服务】App Service 的.NET Version选择为.NET6,是否可以同时支持运行ASP.NET V4.8的应用呢?
|
9月前
|
程序员 数据库
分享 2 个 .NET EF 6 只更新某些字段的方法
分享 2 个 .NET EF 6 只更新某些字段的方法
206 0
|
9月前
|
数据库
分享一个 .NET EF 6 扩展 Where 的方法
分享一个 .NET EF 6 扩展 Where 的方法
|
9月前
|
开发框架 前端开发 算法
分享 .NET EF6 查询并返回树形结构数据的 2 个思路和具体实现方法
分享 .NET EF6 查询并返回树形结构数据的 2 个思路和具体实现方法
145 0
|
9月前
|
开发框架 中间件 .NET
分享 ASP.NET Core Web Api 中间件获取 Request Body 两个方法
分享 ASP.NET Core Web Api 中间件获取 Request Body 两个方法
346 0