1. 程式人生 > >Dsoframer控制元件實現office線上編輯

Dsoframer控制元件實現office線上編輯

程式碼 


Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->  實現方法如下:

   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函式,可以查詢。