惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Stack Overflow Blog
Stack Overflow Blog
T
Threatpost
AWS News Blog
AWS News Blog
小众软件
小众软件
美团技术团队
L
Lohrmann on Cybersecurity
Hacker News: Ask HN
Hacker News: Ask HN
Security Latest
Security Latest
Jina AI
Jina AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
宝玉的分享
宝玉的分享
A
Arctic Wolf
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
爱范儿
爱范儿
The Cloudflare Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
有赞技术团队
有赞技术团队
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
I
InfoQ
V
Visual Studio Blog
N
Netflix TechBlog - Medium
Latest news
Latest news
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
H
Heimdal Security Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Cisco Talos Blog
Cisco Talos Blog
L
LINUX DO - 最新话题
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threat Research - Cisco Blogs
S
Secure Thoughts
The Hacker News
The Hacker News
S
Schneier on Security
博客园 - 【当耐特】
T
The Exploit Database - CXSecurity.com
博客园_首页
N
News | PayPal Newsroom
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

博客园 - 冰峰剑心

android上传图片至服务器 使用LocationManager来获取移动设备所在的地理位置信息 android上传图片、视频、文件,服务端使用wcf接收 无法为类型 CuteEditor.Editor 授予有效的许可证。 url 编码 中文|c# js url传参中文乱码解决方案 - 冰峰剑心 项目管理有感之需求调研 WINDOWSXP文件夹右键属性没有“安全”选项卡的解决 sql语句中日期时间格式化查询 sql isnull函数 Aspnet_regsql 碰到的问题解决 发布前禁用调试 sql coalesce()函数、datalength()函数介绍及应用 subsnic实例! .NET2.0 验证控件常用的正则表达式- 站长分享站 SubSonic的sql插入 C#验证控件的使用方法 //生成六位随机数字 C#日期函数所有样式大全 config的配置
DSO Framer _ WebForm 使用
冰峰剑心 · 2010-04-15 · via 博客园 - 冰峰剑心

转载  DSO Framer _ WebForm 使用 收藏

DSO Framer _ WebForm 使用

一、先注册一下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文档了。