兩個 System.IO.FileInfo 的 Extension Method

using System.IO;
using System.Text;

namespace FileService
{
    
public static class ExtensionMethods
    {
        
public static string MD5Code(this FileInfo fileInfo)
        {
            var data 
= fileInfo.BinaryData();

            
byte[] hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(data);

            var builder 
= new StringBuilder();

            
foreach (var b in hash)
            {
                builder.AppendFormat(
"{0:x2}", b);
            }
            
return builder.ToString();
        }

        
public static byte[] BinaryData(this FileInfo fileInfo)
        {
            
return File.ReadAllBytes(fileInfo.FullName);
        }

    }
}

 

抓檔案的binary 及 MD5

posted @ 2011-08-31 20:02  胖胖安  阅读(395)  评论(0)    收藏  举报