dsoframer控件实现office在线编辑<转>
最近在做一个基于B/S的程序(c#语言),程序中希望实现客户端打开服务器的一个word文档,修改后保存在服务器,最后用dsoframer组件完成了这个功能。
代码
实现方法如下: 1、下载控件并添加到工具箱中。 2、页面实现方法 <%@ Page Language="C#" AutoEventWireup="true" Codebehind="WebForm1.aspx.cs" Inherits="zzuoa.web.dsoframer.WebForm1" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>无标题页</title> <script language="javascript" type="text/javascript"> function openword() { document.all.FramerControl1.Open("http://localhost:2473/web/DownFile/1.doc",false,"Word.Document"); } function SaveDoc() { var returnValue; // 保存页面的返回值 document.all.FramerControl1.HttpInit(); // 初始化Http引擎 // 添加相应的Post元素 document.all.FramerControl1.HttpAddPostString("11", "22"); // 添加上传文件 document.all.FramerControl1.HttpAddPostCurrFile("Filedate ", ""); // 提交上传文件 returnValue = document.all.FramerControl1.HttpPost("../dsoframer/saveword.aspx"); if ("true" == returnValue) { alert("文件上传成功"); } else { alert("文件上传成功") } } function FramerControl1_BeforeDocumentSaved() { if (confirm("是否保存到服务器")) { SaveDoc(); } } </script> <script language="javascript" for="FramerControl1" event="BeforeDocumentSaved"> <!-- FramerControl1_BeforeDocumentSaved() //--> </script> </head> <body onload="openword();"> <form id="Form1" method="post" enctype="multipart/form-data" runat="server"> <div> <object id="FramerControl1" codebase="dsoframer.cab" height="100%" width="99%" classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" lang="chn"> <param name="BorderStyle" value="1"> <param name="TitlebarColor" value="52479"> <param name="TitlebarTextColor" value="0"> <param name="Menubar" value="1"> </object> </div> </form> </body> </html> saveword.aspx页面后台代码实现保存word到服务器 using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Text; namespace zzuoa.web.dsoframer { public partial class saveword : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { BinaryReader bReader = new BinaryReader(Request.InputStream); string strTemp = Encoding.GetEncoding("iso-8859-1").GetString( bReader.ReadBytes((int)bReader.BaseStream.Length), 0, (int)bReader.BaseStream.Length); string match = "Content-Type: application/msword\r\n\r\n"; int pos = strTemp.IndexOf(match) + match.Length; bReader.BaseStream.Seek(pos, SeekOrigin.Begin); string newFile = Server.MapPath("~/web/DownFile/1.doc"); FileStream newDoc = new FileStream(newFile, FileMode.Create, FileAccess.Write); BinaryWriter bWriter = new BinaryWriter(newDoc); bWriter.BaseStream.Seek(0, SeekOrigin.End); while (bReader.BaseStream.Position < bReader.BaseStream.Length - 38) bWriter.Write(bReader.ReadByte()); bReader.Close(); bWriter.Flush(); bWriter.Close(); } } }
在百度文库中有几篇关于dsoframer组件的文章,写了组件的一些api函数,可以供大家参考查询。 原文地址:http://hi.baidu.com/fdsfsd%B1%F9%D3%EA/blog/item/f86fb533a4ebe695a8018e53.html |