二进制数据转换为word文件

/// 
        /// 二进制数据转换为word文件
        /// 
        /// 二进制数据
        /// word文件名
        /// word保存的相对路径
        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;
        }


你可能感兴趣的:(C#)