`
yes809
  • 浏览: 5089 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

DSOFramer的使用 .

阅读更多
http://blog.csdn.net/phqm/article/details/2120084

DSOFramer的使用 .
分类: C#2.0 2008-02-25 21:28 4260人阅读 评论(6) 收藏 举报
一、先注册一下DSOFramer.ocx

    操作:将DSOFramer.ocx复制到C:/windows/system32目录下,

         开始->运行->regsvr32 DSOFramer.ocx , 系统会提示DSOFramer.ocx中的DllRegisterServer成功。

二、添加DSOFramer.ocx到你的项目中

    操作:先说明一下,我用VS 2005 ,其他VS版本可能操作会有不同,操作应该也类似自己试试,问题应该不大。
          在你要访问DSOFramer.ocx的目录上点选右键菜单中的“添加现有项”,找到DSOFramer.ocx,确定。


三、在网页中加载DSOFramer

     新建Office.aspx

    添加如下代码:
     <object id="MyOffice" name = "MyOffice" style="LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%"
    classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" codebase="dsoframer.ocx#version=2,2,0,0" >
    </object>

     [注]:VS 2005对语法的要求贼多,什么ID的值要用""括起来啦,<object>不能大写啦,……
           没什么大碍,但是很烦人,简直就是微软版的唐僧,我给大家提供的代码是修改过的,VS不会有哪些废话了。

     然后再body中加入onload事件的处理函数

                   <body onload="show_word();">

     再在<head></head>中间加入函数体


     <script language="javascript" type="text/javascript">
        <!--

        function show_word() {
                var str=window.location.search;
                var pos_start=str.indexOf("id")+3;
                if (pos_start == 2)
                return ;
       
                var id = "http://localhost/Getdc.aspx?id=" + str.substring(pos_start);
                document.all. MyOffice.Open( id,false, "Word.Document");
        }

        // -->
        </script>


四、编制Getdc.aspx.cs文件
      建立Getdc.aspx文件,VS会同时建立与之关联的Getdc.aspx.cs文件

      先加入命名空间
        using System.Data.SqlClient;
        using System.Data.SqlTypes;

      编辑Getdc.aspx.cs的Page_Load函数;
      protected void Page_Load(object sender, EventArgs e)
      {
        int pid = Convert.ToInt32(Request["id"]);

        SqlConnection myConnection = new SqlConnection("Data Source=/"localhost/";Initial Catalog=/"demo/";Persist Security Info=True;User ID=demo;Password=demo");//数据库的相关设置自己改吧,我就不废话了
        SqlCommand mycommand = myConnection.CreateCommand();
        myConnection.Open();

        mycommand.CommandText = "SELECT filedata " +
            " FROM Table_word WHERE (ID = " + pid.ToString() + ") ";//其中filedata的数据库类型是varbinary(MAX)
        SqlDataReader myReader = mycommand.ExecuteReader();
        myReader.Read();
        SqlBinary binaryStream = myReader.GetSqlBinary(0);
        myReader.Close();
        myConnection.Close();

        Response.BinaryWrite(binaryStream.Value);
    }

     至此,只要你指定的ID没问题,就应该可以加载Word文档了。



五、建立保存文档的按钮


        在Office.aspx中添加按钮

        <input id="Button1" type="submit" value="保存" onclick="return Submit_upload_onclick()" />

        再建立一个input

            <input type="file" name="File" id = "File"/>


        然后添加Submit_upload_onclick()函数:

        function Submit_upload_onclick() {
        var str=window.location.search;
        var pos_start=str.indexOf("id")+3;
        if (pos_start == 2)
        return ;

        document.all.MyOffice.HttpInit();
        document.all.MyOffice.HttpAddPostCurrFile("File", "");
        var id = "http://localhost/Savedc.aspx?id=" + str.substring(pos_start);
        document.all.MyOffice.HttpPost(id);
        }

六、编制Savedc.aspx.cs文件
      建立Savedc.aspx文件,VS会同时建立与之关联的Savedc.aspx.cs文件

      先加入命名空间
        using System.Data.SqlClient;
        using System.Data.SqlTypes;

      编辑Savedc.aspx.cs的Page_Load函数;

    protected void Page_Load(object sender, EventArgs e)
    {
        int pid = Convert.ToInt32(Request["id"]);
        Byte[] source_bin = Request.BinaryRead(Request.TotalBytes);

        //---------------------------------------------------------------------------------------
       int i, loop, again = -1, file_begin = -1;
         for (i = 0; i < Request.TotalBytes; i++)
        {
            if (source_bin[i] == 13)
                if (source_bin[i + 1] == 10)
                    break;
        }
        Byte[] MyHeader = new Byte[i];
        for (loop = 0; loop < i; loop++)
            MyHeader[loop] = source_bin[loop];

        for (i += 2; i < Request.TotalBytes; i++)
        {
            if (source_bin[i] == 13)
                if (source_bin[i + 1] == 10)
                    if (source_bin[i + 2] == 13)
                        if (source_bin[i + 3] == 10)
                            break;
        }

        file_begin = i + 4;
        for (i = file_begin; i < Request.TotalBytes; i++)
        {
            for (loop = 0; loop < MyHeader.Length; loop++)
                if (source_bin[i + loop] != MyHeader[loop])
                    break;
            if (loop >= MyHeader.Length)
            {
                break;
            }
        }

        Byte[] result = new Byte[i - file_begin];
        //这是个不得已的办法,用循环肯定会慢,但我不会其他方法
        //希望高手完善
        for (loop = file_begin; loop < i - file_begin; loop++)
            result[loop - file_begin] = source_bin[loop];

        //---------------------------------------------------------------------------------------
        //以上代码将word文档从二进制流中提取出来,存储在result[]中,方法虽笨,肯定好使
        //本人不懂VB,更不懂Java,
        //上面代码是我楞从梁无惧用VB写的无惧上传类V2.0里挑选有用的部分翻译成C#的,泪ing……
        //看看人家梁兄,多无私,给同行提供这么好的东东
        //我在网上找了N + 1天,就TM没找到C#版的,再泪ing……
        //现在提供给大家,希望我是最后一个为此郁闷的人


        SqlConnection myConnection = new SqlConnection("Data Source=/"localhost/";Initial Catalog=/"demo/";Persist Security Info=True;User ID=demo;Password=demo");//数据库的相关设置自己改吧
        SqlCommand mycommand = myConnection.CreateCommand();
        mycommand.CommandText = "UPDATE Table_word SET filedata = @myfiledata , b_finished = 1 WHERE (ID = @myID)";
        mycommand.Parameters.Add("@myfiledata", SqlDbType.VarBinary, 0, "filedata");
        mycommand.Parameters.Add("@myID", SqlDbType.Int, 4, "ID");

        SqlDataAdapter mydpt;
        DataSet myds = new DataSet();

        mydpt = new SqlDataAdapter("SELECT ID ,filedata , b_finished FROM Table_copy  WHERE (ID = " + Request["id"] + ")", myConnection);
        myConnection.Open();

        mydpt.UpdateCommand = mycommand;
        mydpt.Fill(myds);
        DataTable mydt = myds.Tables[0];
        DataRow myrow;
        myrow = mydt.Rows[0];
        myrow.BeginEdit();
        myrow["filedata"] = result;
        myrow.EndEdit();

        mydpt.Update(myds);
        myConnection.Close();/**/
          }


        至此,只要你指定的ID没问题,就应该可以保存Word文档了。




编辑Savedc.aspx.cs的Page_Load函数;
protected void Page_Load(object sender, EventArgs e)
------------------------------------------------------------------------------
果然是ASP的写法。不过c#里面不需要这样,C# 提供了这样的接口

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.Data.SqlClient;
using System.Data.OleDb;
using System.IO;

public partial class upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
                //ID为文档的主键,如果ID不为空,则更新数据,否则新建一条记录
        string ID = Request.Params["ID"];
        string DocID,DocTitle,DocType;
        DocID = "test";
        DocTitle = "test";
        if(ID != null && ID !=""){
            DocID = Request.Params["DocID"];
            DocTitle = Request.Params["DocTitle"];
        }
        DocType = Request.Params["DocType"];
        if(DocType == "")
            DocType =  "doc";

        DocType = DocType.Substring(0, 3);
        if (Request.Files.Count > 0)
        {
                OleDbConnection objConnection;
   
                HttpPostedFile upPhoto = Request.Files[0];
                int upPhotoLength = upPhoto.ContentLength;
                byte[] PhotoArray = new Byte[upPhotoLength];
                Stream PhotoStream = upPhoto.InputStream;
                PhotoStream.Read(PhotoArray, 0, upPhotoLength); //这些编码是把文件转换成二进制的文件

                string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
                strConnection += @"Data Source=" + this.Server.MapPath("des.mdb");
                objConnection = new OleDbConnection(strConnection);
                objConnection.Open();

                string strSql;
                if (ID != null && ID != "")
                {
                    strSql = "update Doc Set DocContent  = @FImage where id = " + ID;                
                    OleDbCommand comd = new OleDbCommand(strSql, objConnection); //执行sql语句
                    comd.Parameters.Add("@FImage", OleDbType.Binary);
                    comd.Parameters["@FImage"].Value = PhotoArray;
                    comd.ExecuteNonQuery(); //执行查询   
                   
                }
                else
                {
                    strSql = "Insert into Doc(DocID,DocTitle,DocType,DocContent) values(@DocId,@DocTitle,@DocType,@FImage)";
                    OleDbCommand comd = new OleDbCommand(strSql, objConnection); //执行sql语句
                    if(DocID != "")
                        comd.Parameters.Add("@DocId", OleDbType.VarChar, 20).Value = DocID;  //定义参数同时给它赋值
                    if (DocTitle != "")
                        comd.Parameters.Add("@DocTitle", OleDbType.VarChar, 50).Value = DocTitle;
                    comd.Parameters.Add("@DocType", OleDbType.VarChar, 10).Value = DocType;
                    comd.Parameters.Add("@FImage", OleDbType.Binary);
                    comd.Parameters["@FImage"].Value = PhotoArray;
                    comd.ExecuteNonQuery(); //执行查询
                }
                objConnection.Close();  //关闭数据库
                Response.Write("OK");
                Response.End();
            //-------------------------------------------
        }else{
            Response.Write("No File Upload!");
        }
    }
}
分享到:
评论

相关推荐

    dsoframer2.3.0.0.rar_DsoFramer 2.3_Dsoframer?2.3.0.0_V2 _dsofram

    1. 使用DSOframer时,确保用户的计算机上已经安装了对应版本的Microsoft Office,因为DSOframer依赖于Office组件来处理文档。 2. 对于安全性要求较高的环境,需要考虑DSOframer的权限设置,避免恶意代码的执行。 3...

    DSOframer2007.CAB

    DSOframer2007.CAB 微软官方office控件,比 DSOframer.CAB 更稳定,更好的兼容office2007以上版本

    DsoFramer.ocx接口及说明

    DsoFramer.ocx接口及说明 word在线编辑,加密,书签,等2. HRESULT Open([in] VARIANT Document, [in, optional] VARIANT ReadOnly, [in, optional] VARIANT ProgId, [in, optional] VARIANT WebUsername, [in, ...

    dsoframer2.3.ocx.rar

    1. 安装控件:将dsoframer.ocx文件注册到系统中,一般可以通过命令行工具regsvr32来完成。 2. 引用控件:在项目中添加对DSOFramer的引用,使程序能够识别并调用该控件。 3. 编写代码:利用控件的API实现与Word的交互...

    dsoframer.ocx控件以及使用方法

    **dsoframer.ocx控件详解与使用指南** **一、dsoframer.ocx控件介绍** dsoframer.ocx是一款ActiveX控件,主要用于在Windows应用程序中嵌入和显示各种文档,如Word、Excel、PDF等。通过这款控件,开发者可以轻松地...

    dsoframer.ocx 2.3.0.2版本

    在C#编程环境中,DSOFramer.ocx可以通过COM互操作性来使用。这意味着C#开发者无需了解底层的COM细节,只需简单地引用该控件,就可以在C#项目中调用其功能。这样大大简化了在.NET应用程序中嵌入Office文档的工作流程...

    dsoframer.ocx最新版本

    关于如何使用DSOFramer.ocx,`dsoframer.ocx使用方法.txt`文件很可能是提供详细教程或者API文档的文本文件。这个文件可能会涵盖以下内容: 1. **安装与注册**:如何将DSOFramer.ocx控件添加到开发环境中,以及如何...

    dsoframer.ocx 2.3.0.2

    dsoframer.ocx 2.3.0.2 目前最细版本 本exe为静默安装,双击无反应属于正常现象,可使用360压缩,解压exe获取里面对应的ocx

    dsoframer.ocx控件最新版支持office2016

    在使用**DSOFramer.ocx**之前,开发者可能会遇到一个问题:当尝试在WinForm应用中嵌入低版本的Word时,文档会直接以独立的Word应用程序窗口打开,这破坏了应用的统一性和用户体验。DSOFramer控件有效解决了这一问题...

    DsoFramer V2.3.0.2

    dsoframer.ocx 2.3.0.0 Release comments: 1、增加对OFFICE2007的支持 2、删除2个文件:msword9.h/msword9.cpp ///////////////////////////////////////////////////// Issued by jiangzuixian on sep 19,2009 ...

    dsoframer.ocx.zip

    dsoframer.ocx 是一个ActiveX控件,它在Windows环境中广泛使用,主要功能是嵌入和显示各种文档格式,如PDF、Word、Excel等,使得应用程序能够无缝集成文档查看功能。本文将深入探讨dsoframer.ocx文件的原理、作用...

    dsoframer.ocx控件

    **使用 C# 集成 DSOFramer.ocx** 在 C# 中集成 DSOFramer.ocx,首先需要在项目中添加对该控件的引用。这通常包括以下几个步骤: 1. 下载并安装 DsoFramer_KB311765_x86.exe,这会将控件注册到系统,并可能包含必要...

    DsoFramer-V2.3.0.1.rar_DSOframer 开发_DsoFramer_dsoframer 2.3.0.1_

    5. `dsoframer.dsp`和`dsoframer.dsw`:这是Visual Studio的项目文件,用于构建和管理DSOFramer的源代码。 6. `mainentry.cpp`:可能包含了DSOFramer的主要入口点和初始化代码,是DSOFramer运行的起点。 7. `class...

    dsoframer.ocx_DsoFramer_

    【标题】"dsoframer.ocx_DsoFramer_" 指的是一个特定的控件,名为 DsoFramer,它是一个ActiveX组件。在IT领域,ActiveX技术是微软开发的一种组件对象模型(COM),用于在Windows环境中创建交互式、可重用的软件组件...

    dsoframer.ocx 2.3.0.1版

    dsoframer.ocx 2.3.0.1版

    dsoframer.ocx 2.3.0.0 含源码和ocx

    dsoframer.ocx 2.3.0.0 Release comments: 1、增加对OFFICE2007的支持 2、删除2个文件:msword9.h/msword9.cpp 编译生成了dsoframer.ocx 1、需要安装VC++6 2、需安装office2007 3、需安装wps office 2005 4、注意ms...

    DsoFramer_V2.3.0.1.rar_DsoFramer vb_DsoFramer_V2.3.0.0_DsoFramer

    该软件实现了能够在浏览器窗口中直接编辑MS Office、Kingsoft WPS等复合文档并保存到Web服务器。控件采用标准互联网协议,支持任意后台Web服务器(iis, domino, webaphere, apache等),任意后台操作系统(win2k...

    dsoframer.rar

    《深入解析DSOFramer控件:dsoframer.ocx 2.3.0.2》 DSOFramer控件,全称为Dynamic Server Object Framer,是微软开发的一款用于在ActiveX环境中嵌入Web浏览器控件的技术。在本文中,我们将深入探讨这款控件的最新...

    dsoframer2.rardsoframer2.rardsoframer2.rardsoframer2..rar

    1. **DSOFramer2的主程序文件**:这可能是一个DLL或EXE文件,是DSOFramer2的核心组件,供其他应用程序调用和使用。 2. **文档和手册**:可能包含了关于如何使用DSOFramer2的PDF或HTML文件,包括API参考、示例代码和...

Global site tag (gtag.js) - Google Analytics