文件MD5 并复制到剪切板
Posted 2eggs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件MD5 并复制到剪切板相关的知识,希望对你有一定的参考价值。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace FileMd5 { public partial class GetMd5 : Form { public GetMd5() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { button1Md5.Text = "Get MD5"; } /// <summary> /// 获取文件MD5值 /// </summary> /// <param name="fileName">文件绝对路径</param> /// <returns>MD5值</returns> public static string GetMD5(string fileName) { try { FileStream file = new FileStream(fileName, FileMode.Open); System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] retVal = md5.ComputeHash(file); file.Close(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < retVal.Length; i++) { sb.Append(retVal[i].ToString("x2")); } return sb.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } private void Button1_Click(object sender, EventArgs e) { try { button1Md5.Text = "ing"; string strMd5 = GetMD5(textBox1Path.Text.ToString().Trim()); Clipboard.SetDataObject(strMd5); textBox2Md5.Text = "已复制到剪切板 " + strMd5; } catch (Exception ex) { textBox2Md5.Text = "err"; } finally { button1Md5.Text = "Get MD5"; } } } }
以上是关于文件MD5 并复制到剪切板的主要内容,如果未能解决你的问题,请参考以下文章
Python中将pandas的dataframe拷贝到剪切板并保持格式实战:to_clipboard()函数复制到Excel文件复制到文本文件(默认是tsv格式)复制到文本文件(设置逗号分隔符)