文件和二进制流的相互转换
/// <summary>
/// 把文件转化为二进制流
/// </summary>
/// <param name="Path">文件路径</param>
/// <returns></returns>
public static byte[] ConvertToBinary(string Path)
{
FileStream stream = new FileInfo(Path).OpenRead();
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
return buffer;
}
#endregion
byte[] file = Convert.FromBase64String(datass);
//保存文件
string FilePath = "D:\\杭州集广OA\\文件交换\\XHQJYJ\\传阅板\\Test.docx";
FileStream fstream = File.Create(FilePath, file.Length);//创建文件流
try
{
fstream.Write(file, 0, file.Length);//把二进制流数据写入文件
fstream.Close();
}
/// 把文件转化为二进制流
/// </summary>
/// <param name="Path">文件路径</param>
/// <returns></returns>
public static byte[] ConvertToBinary(string Path)
{
FileStream stream = new FileInfo(Path).OpenRead();
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
return buffer;
}
#endregion
byte[] file = Convert.FromBase64String(datass);
//保存文件
string FilePath = "D:\\杭州集广OA\\文件交换\\XHQJYJ\\传阅板\\Test.docx";
FileStream fstream = File.Create(FilePath, file.Length);//创建文件流
try
{
fstream.Write(file, 0, file.Length);//把二进制流数据写入文件
fstream.Close();
}