Get Gravatar Path - CSharp System.IO

CSharp examples for System.IO:File Path

Description

Get Gravatar Path

Demo Code


using System.Text;
using System.Security.Cryptography;

public class Main{
        public static string GetGravatarPath(this string email)
        {/*from  w  w w.  j ava  2s . com*/
            var response = string.Empty;
            if (!string.IsNullOrEmpty(email))
            {
                byte[] data = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(email));
                StringBuilder sBuilder = new StringBuilder();
                for (int i = 0; i < data.Length; i++)
                {
                    sBuilder.Append(data[i].ToString("x2"));
                }

                response = sBuilder.ToString();
            }

            return "http://www.gravatar.com/avatar/" + response;
        }
}

Related Tutorials