/// <summary> /// 文件转换为Base64二进制流 /// </summary> /// <param name="FilePath"></param> /// <returns></returns> public static string FileToBase64(string FilePath) { FileStream fileStream = File.Open(FilePath, FileMode.OpenOrCreate); byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); fileStream.Close(); return Convert.ToBase64String(buffer); }
/// <summary> /// Base64二进制流还原文件 /// </summary> /// <param name="FilePath">存放文件的路径</param> /// <param name="StringBase64">文件Base64二进制流</param> public static void Base64TeCode(string FilePath,string StringBase64) { FileStream fileStream = new FileStream(FilePath, FileMode.Create); byte[] buffer = Convert.FromBase64String(StringBase64); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); }