C#实现base64 字符串转文件存储
2018-07-20 来源:open-open
把一个base64 字符串解码后存为另外一个文件
void Main() { ConvertFromBase64String(); } void ConvertFromBase64String() { string fileName = GetSaveFileName(); if ( fileName == null ) { MessageBox.Show("No file name specified"); } else { ConvertFromBase64String(fileName); } } void ConvertFromBase64String(string saveFileName) { ConvertFromBase64String(Clipboard.GetText(), saveFileName); } void ConvertFromBase64String(string input, string saveFileName) { var contents = Convert.FromBase64String(input); using (var fs = new FileStream(saveFileName, FileMode.Create, FileAccess.Write)) { fs.Write(contents, 0, contents.Length); fs.Flush(); } } string GetFileName(FileDialog fd) { bool? result = fd.ShowDialog(); if ( result != null && result.Value ) { return fd.FileName; } return null; } string GetOpenFileName() { var ofd = new OpenFileDialog { Title = "Select text file", Filter = "All files (*.*)|*.*", RestoreDirectory = true }; return GetFileName(ofd); } string GetSaveFileName() { var sfd = new SaveFileDialog { Title = "Save file as", Filter = "All files (*.*)|*.*", RestoreDirectory = true }; return GetFileName(sfd); }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐