当前位置:软件学习 > Word >>

c# word文档与二进制数据的相互转换

最近项目出使用到了将word文档以二进制的方法存到数据库中,并再次读取出二进制数据转换为word文档。最后总结了一下,不多说看示例方法:
 

\代码
        /// <summary>
        /// 二进制数据转换为word文件
        /// </summary>
        /// <param name="data">二进制数据</param>
        /// <param name="fileName">word文件名</param>
        /// <returns>word保存的相对路径</returns>
        public string ByteConvertWord(byte[] data, string fileName)
        {
            string savePath = @"SystemWord"+FormatNowTime(2)+@"";

            if (!System.IO.Directory.Exists(GetPath() + savePath))
            {
                Directory.CreateDirectory(GetPath() + savePath);
            }
            savePath += fileName + ".doc";
            string filePath = GetPath() + savePath;

            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 savePath;
        }

        /// <summary>补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,