描述:先已将一个Wrod文档以二进制的形式保存到了 数据库 中请问如何可以实现将二进制直接转为一个word文档。

解决方案 »

  1.   

    给点意见呗。 byte[] content = “二进制数据”;
                Response.ClearHeaders();
                Response.ClearContent();
                Response.Clear();
                Response.ContentType = "Application/msword";
                //Response.BinaryWrite(content); 下面该怎么写...
      

  2.   


    HttpContext.Current.Response.BinaryWrite(content);
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
      

  3.   

    以前我也遇到过这个问题,大致是这样的先将数据读取到dr
    SqlDataReader dr = com.ExecuteReader(); 然后if (dr.Read()) 

    Page.Response.ContentType = dr["type"].ToString(); 
    Page.Response.BinaryWrite(Convert.FromBase64String(dr["filedata"].ToString())); Page.Response.End(); 
    } 数据以text类型存储
      

  4.   

    先谢谢两位,我现在想在Winform中实现,把从数据库中读取word的二进文件数据换为。
    请问还有没有其他的方法可用?
      

  5.   

    找到一个方法,不幸的是,打开是乱码: protected string ConvertWord(byte[] data)
            {
                string filepath = "d:/1.doc";
                FileStream fs;
                if (System.IO.File.Exists(filepath))
                {
                    fs = new FileStream(filepath, FileMode.Truncate);
                }
                else
                {
                    fs = new FileStream(filepath, FileMode.CreateNew);
                }
                BinaryWriter br = new BinaryWriter(fs);
                br.Write(data, 0, data.Length);
                br.Close();
                fs.Close();
                return "";
            }
    引用地址:http://topic.csdn.net/u/20080415/11/048deb7e-b0c2-4a20-94a5-88be74ce47f0.html
      

  6.   

    搞定,这个方法可以。
    原来数据库中的二进制文件加密啦。
    解密后将二进制数据传入该测试方法即可。  protected void ConvertWord(byte[] data)
            {
                string filepath = "d:/a.doc";
                FileStream fs = new FileStream(filepath, FileMode.CreateNew);
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(data, 0, data.Length);
                bw.Close();
                fs.Close();        }
      

  7.   

    接着问:
    --------
    如何跟word文件路径,将其转换为二进制保存到数据库。
      

  8.   


    ------------------------将文件转换为二进制,并保存到数据库中-----------------------------------------------------            string strResult = strPath + @"\result.doc";            System.IO.FileStream fs = new System.IO.FileStream(@strResult, System.IO.FileMode.Open);
                fs.Position = 0;
                byte[] content = new byte[fs.Length];
                fs.Read(content, 0, (int)fs.Length);
                fs.Close();
                fluidDesignDoc.qhse1 = content;//其中qhse1在数据库中保存的类型为OLE对象
                IFluidDesignDocManager manager = new FluidDesignDocManager();
                manager.UpdateFluidDesignDoc(fluidDesignDoc);-------------------------将二进制数据转化为指定位置文件----------------------------------------private void getFile(byte[] content, string filePath)
            {
                string fileName = filePath;            if (System.IO.File.Exists(fileName))
                {
                    System.IO.File.Delete(fileName);
                }
                //FileStream sw = new FileStream(@fileName, FileMode.Create);
                //StreamWriter fs = new StreamWriter(sw, Encoding.UTF8);
                //fs.Write(entity.Content);
                System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
                fs.Write(content, 0, content.Length);
                fs.Flush();
                fs.Close();
                fileName = System.IO.Path.Combine(Application.StartupPath, fileName);
            }
      

  9.   

    谢谢,liuxing19870629
     
    我也试出一种方法:        private byte[] wordConvertByte(string wordPath)
            {
                byte[] bytContent = null;
                System.IO.FileStream fs = null;
                System.IO.BinaryReader br = null;
                try
                {
                    fs = new FileStream(wordPath, System.IO.FileMode.Open);
                }
                catch
                {
                }
                br = new BinaryReader((Stream)fs);
                bytContent = br.ReadBytes((Int32)fs.Length);            return bytContent;
            }
    通过上方法的测试可以protected void ConvertWord(byte[] data)
            {
                string filepath = "d:/a.doc";
                FileStream fs = new FileStream(filepath, FileMode.CreateNew);
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(data, 0, data.Length);
                bw.Close();
                fs.Close();        }
      

  10.   

    bw.Write(data, 0, data.Length); 中的0 指的不是"application/msword" ?