asp.net(c#)下读取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();

时间: 2024-08-31 00:53:55

asp.net(c#)下读取word文档的方法小结_实用技巧的相关文章

ASP.NET防止页面刷新的两种解决方法小结_实用技巧

方法有二,总结如下: 第一方法: 直接在CS代码里敲: Response.Buffer = true; Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1); Response.Expires = 0; Response.CacheControl = "no-cache"; 当有人想按后退时页面已过期,效果就达到了 第二方法: SubmitOncePage:解决刷新页面造成的数据重复提交问题(网上资料) 执行过postback操作

ASP.NET对无序列表批量操作的三种方法小结_实用技巧

本篇介绍服务器端ASP.NET批量操作基于原生html标签的无序列表的三种方法. 方法一,将li元素做成html控件,加上id,用FindControl方法. aspx代码: 复制代码 代码如下: <form id="form1" runat="server"> <ul> <li id="li1" runat="server">初始值1</li> <li id="

python读取word文档的方法

  本文实例讲述了python读取word文档的方法.分享给大家供大家参考.具体如下: 首先下载安装win32com ? 1 2 3 4 5 6 from win32com import client as wc word = wc.Dispatch('Word.Application') doc = word.Documents.Open('c:/test') doc.SaveAs('c:/test.text', 2) doc.Close() word.Quit() 这种方式产生的text文档

PHP创建word文档的方法(平台无关)_php技巧

本文实例讲述了PHP创建word文档的方法.分享给大家供大家参考,具体如下: 关于用PHP生成word,在网上找了很多资料,有调用COM组件生成的,有安装PHP扩展生成的.都不免麻烦,以下为比较简洁的一种方法,且可跨平台. 以下为详细代码: class.word.php <?php class Word{ function start(){ ob_start(); //打开输出控制缓冲 echo '<html xmlns:o="urn:schemas-microsoft-com:of

asp.net读取Word文档属性方法

'对自定义属性进行读取  代码如下 复制代码          Dim Properties = SourceDoc.CustomDocumentProperties             Dim PropertyType As Type = Properties.GetType         Try             Dim Authorprop = PropertyType.InvokeMember("Item", Reflection.BindingFlags.Defa

ASP.NET读取XML文件4种方法分析_实用技巧

方法一 :使用XML控件 代码 复制代码 代码如下: <% @ Page Language="C#"%> <html> <body> <h3><font face="Verdana">读取XML方法一</font></h3> <from runat=server> <asp:Xml id="xml1" DocumentSource="g

ASP.NET MVC下的四种验证编程方式[续篇]_实用技巧

在<ASP.NET MVC的四种验证编程方式>一文中我们介绍了ASP.NET MVC支持的四种服务端验证的编程方式("手工验证"."标注ValidationAttribute特性"."让数据类型实现IValidatableObject或者IDataErrorInfo"),那么在ASP.NET MVC框架内部是如何提供针对这四种不同编程方式的支持的呢?接下来我们就来聊聊这背后的故事. 一.ModelValidator与ModelVali

Asp.net之TextBox只允许输入数字的方法总结_实用技巧

复制代码 代码如下: <asp:textbox id="TextBox1" onkeyup="if(isNaN(value))execCommand('undo')" runat="server" Width="80px" onafterpaste="if(isNaN(value))execCommand('undo')"></asp:textbox> 其实服务器控件也能加上onke

asp.net创建XML文件的方法小结_实用技巧

本文实例讲述了asp.net创建XML文件的方法.分享给大家供大家参考,具体如下: 方法一:按照XML的结构一步一步的构建XML文档. 通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法一:按照XML的结构一步一步的构建XML文档. 通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法二:直接定影XML文档,然后保存到文件. 通过"XmlDocumen