rt

解决方案 »

  1.   

    坐沙发了,你把数据库里面的内容读取出来,然后再进行转换不就可以了,我原来搞过word里面放声音和文字还有图象的东西放在数据库里的,应该和你的差不多吧
      

  2.   

    下面是我写的一个类,我贴出来
    using System;
    using System.IO;
    using System.Data;
    using System.Data.SqlClient;
    namespace DoitCNOA.Gwmod.Gwnz
    {
    /// <summary>
    /// Binary 的摘要说明。
    /// </summary>
    public class Binary
    {
    protected System.Data.SqlClient.SqlConnection conn;
    /// <summary>
    /// get byte[] of file
    /// </summary>
    /// <param name="filepath">docupath</param>
    /// <returns>return byte[] of docu</returns>
    public byte[] GetDocu(string filepath)
    {
    System.IO.FileStream fs=new FileStream(filepath,System.IO.FileMode.Open,System.IO.FileAccess.Read);
    byte[] docu=new byte[Convert.ToInt32(fs.Length)];
                fs.Read(docu,0,Convert.ToInt32(fs.Length));
    fs.Close();
    return docu;
    }
            /// <summary>
            /// 存储模板操作;
            /// </summary>
            /// <param name="filepath">dotpath</param>
            /// <param name="dotname">dotname</param>
            /// <param name="tempid">update the rowid(default:0--insert;**--update)</param>
            /// <param name="sign">区别存储过程的标志</param>
    public void operdot(string filepath,string dotname,int tempid,int sign)  
    {
    conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connstr"].ToString());
    conn.Open();
    SqlCommand comms=new SqlCommand();
                comms.Connection=conn;
    comms.CommandType=System.Data.CommandType.StoredProcedure;
    byte[] dots=GetDocu(filepath);
    if(sign==1)
    {
    if(tempid==0)
    {
    comms.CommandText="insertblob";
    comms.Parameters.Add("@sign",System.Data.SqlDbType.Int,4);
    comms.Parameters.Add("@typename",System.Data.SqlDbType.VarChar,50);
    comms.Parameters.Add("@dotblob",System.Data.SqlDbType.Image,dots.Length);
    comms.Parameters["@sign"].Value=sign;
    comms.Parameters["@typename"].Value=dotname;
    comms.Parameters["@dotblob"].Value=dots;
    }
    else
    {
    comms.CommandText="updateblob";
    comms.Parameters.Add("@sign",System.Data.SqlDbType.Int,4);
    comms.Parameters.Add("@typename",System.Data.SqlDbType.VarChar,50);
    comms.Parameters.Add("@dotblob",System.Data.SqlDbType.Image,dots.Length);
    comms.Parameters.Add("@id",System.Data.SqlDbType.Int,4);
    comms.Parameters["@sign"].Value=sign;
    comms.Parameters["@typename"].Value=dotname;
    comms.Parameters["@dotblob"].Value=dots;
    comms.Parameters["@id"].Value=tempid;
    }
    }
    if(sign==2)
    {
    //update
    comms.CommandText="updateblob";
    comms.Parameters.Add("@sign",System.Data.SqlDbType.Int,4);
    comms.Parameters.Add("@typename",System.Data.SqlDbType.VarChar,50);
    comms.Parameters.Add("@dotblob",System.Data.SqlDbType.Image,dots.Length);
    comms.Parameters.Add("@id",System.Data.SqlDbType.Int,4);
    comms.Parameters["@sign"].Value=sign;
    comms.Parameters["@typename"].Value=dotname;
    comms.Parameters["@dotblob"].Value=dots;
    comms.Parameters["@id"].Value=tempid; }
        comms.ExecuteNonQuery();
    System.Web.HttpContext.Current.Response.Write("<script>alert('保存成功!');</script>");
    comms.Dispose();
    conn.Close();
    conn.Dispose();
    conn=null;

    }
            /// <summary>
            ///  look templete of dot
            /// </summary>
            /// <param name="sql">select sql</param>
            /// <param name="colname">字段名称</param>
    public void getdot(string sql,string type,string colname,string filename)
    {
    try
    {
    conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connstr"].ToString());
    conn.Open();
    SqlCommand comm=new SqlCommand(sql,conn);
    SqlDataReader r=comm.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
    if(r.Read())
    {
    //type=".dot";
    System.Web.HttpContext.Current.Response.Clear();
    System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition","filename="+System.Web.HttpContext.Current.Server.UrlEncode(r[""+filename].ToString())+type);
    System.Web.HttpContext.Current.Response.ContentType="application/msword";
    System.Web.HttpContext.Current.Response.BinaryWrite((byte[])r[""+colname]);
    }
    System.Web.HttpContext.Current.Response.Flush();
    //System.Web.HttpContext.Current.Response.End();
    r.Close();
    comm.Dispose();
    conn.Close();
    conn.Dispose();
    conn=null;
    }
    catch(System.Exception error)
    {
        System.Web.HttpContext.Current.Response.Write("<script>alert('文档无内容!');</script>");
    return;
    }
    }
       /// <summary>
       /// delete templete
       /// </summary>
       /// <param name="dotid">rowid</param>
    public void deldot(string dotid)
    {
    conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connstr"].ToString());
    conn.Open();
    SqlCommand comm=new SqlCommand("delete from dottype where id="+dotid,conn);
    comm.ExecuteNonQuery();
                System.Web.HttpContext.Current.Response.Write("<script>alert('删除成功!');</script>");
    comm.Dispose();
    conn.Close();
    conn.Dispose();
    conn=null;
    }
            
    }
    }
      

  3.   

    其中public byte[] GetDocu(string filepath)是把上传的文件转成byge[]类型的,其中public void operdot(string filepath,string dotname,int tempid,int sign) 是把byte[]类型的文件保存到数据库中其中public void getdot(string sql,string type,string colname,string filename)是把数据库中的byte[]类型的文件在浏览器上输出的这个就不用说了public void deldot(string dotid),是删除的
      

  4.   

    我觉得如果你已经保存到数据库中的话,你用的只是在IE 上输出,就参考我里面的 getdot过程就应该可以了,关键是这两句
    System.Web.HttpContext.Current.Response.ContentType="application/msword";
    System.Web.HttpContext.Current.Response.BinaryWrite((byte[])r[""+colname]);因为我是 word,所以你只要改成你的类型就可以了
      

  5.   

    哦,我忘记说明一点了,我这里显示到ie中不是以addheader方式读出来的,这种方法我知道,我的意思是在ie里面用类似于richtextbox控件的形式将rtf格式的binary字段显示在网页上,
    http://community.csdn.net/Expert/topic/5086/5086941.xml?temp=.3099634
    这是我昨天发的帖子,谁如果能解决我连这个的分一起给
    http://community.csdn.net/Expert/topic/5080/5080362.xml?temp=.7326929
    这个是我第一次发的。
      

  6.   

    目前为止我正在研究freetextbox里面如何将rtf流变成html的方法,这种方法好像可以将binary字段中的rtf格式流放入ftb显示出来。
      

  7.   

    我原来写过一个com控件,是显示 word的内容的,我不知道你确切的目的是什么,只是要显示到IE中吗?如果只是显示的话,我那个类里面的就可以实现了
      

  8.   

    freetextbox的效果可以用iframe模拟出来的
      

  9.   

    我原来写的控件是用delphi写的,调用word的类库来实现,因为在.net下写的控件用.net框架支持才能用,不是太好,用delphi写的控件调用的是widows的类库,所以通用性比较好
      

  10.   

    我的目的就是在ie里面显示rtf的内容,但是这个显示不是用word环境才能显示的,用System.Web.HttpContext.Current.Response.ContentType="application/msword";
    System.Web.HttpContext.Current.Response.BinaryWrite((byte[])r[""+colname]);
    ie会自动调用word,然后就跑到wrod编辑环境里面去了。我的意思就是要有一个像richtextbox这样的控件在ie的一个部分区域内显示出来。
      

  11.   

    瞧瞧这个,可能有帮助:
    http://www.2mysite.net/blogview.asp?logID=134
      

  12.   

    那你可以自己做个iframe啊,然后在iframe里面实现,只占部分啊,
    比如你在页面中加一个表格
    <table>
    <tr>
    <td>
    <iframe name="iframe" src="./a.aspx" frameborder="0"></iframe>
    </td>
    </tr>
    </table>
    System.Web.HttpContext.Current.Response.ContentType="application/msword";
    这个是显示word的,你的不是word,所以要改一下类型,
      

  13.   

    to bcwchina(修哲)
    你说的方法我试验了一下,用iframe可以显示出来,不过这个显示的实际是调用了word,我的意思是就像看一个图片一样,没有word的边框和菜单,比如象richtextbox那样,而且我从数据库中调用出来的就是一个word文档,我的想法是像一个Label控件一样,用户只能看,不能改。
      

  14.   

    to jedliu(21世纪什么最贵? 人才!)
    我看了一下,由于对rtf的编码规则不是很懂,所以有些地方还是不太清楚。我昨天看msdn中好像有写rtf编码规则的,里面好像就有图片的保存位置。然后我试着在freetextbox中把rtf粘贴过去,通过freetextbox的html转换看到图片的转换位子了。其实我现在想法很简单,只要能够实现向ftb那样显示图片+文字就可以了,实在不行就改造ftb。
      

  15.   

    现在学习rtf,我的初步想法是根据rtf规范将数据库中的二进制流根据规范分别提取成2个部分,1个部分是标准文本,转换码之后存放到textbox控件中,另外一部分是图片部分,直接保存于image控件中,这是一个初步想法,还希望高手们多多指正!