Recently, the project used to save a Word document in binary format to a database, and read and retrieve the binary data again to convert it into a Word document. Finally, I have summarized the following methods:
Code /// <Summary>
/// Convert binary data to a word file
/// </Summary>
/// <Param name = "data"> binary data </param>
/// <Param name = "fileName"> word file name </param>
/// <Returns> relative path of word storage </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>