You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
651 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. namespace Shentun.Utilities
  6. {
  7. public class FileHelper
  8. {
  9. public static string ToBase64(string filename)
  10. {
  11. Stream stream;
  12. string fileBase64;
  13. using (stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
  14. {
  15. byte[] byteData = new byte[stream.Length];
  16. stream.Read(byteData, 0, byteData.Length);
  17. fileBase64 = Convert.ToBase64String(byteData);
  18. stream.Close();
  19. }
  20. return fileBase64;
  21. }
  22. }
  23. }