You can use ShortGuid. Here is an example implementation.
It's good to use ShortGuids in URLs or other places visible to the end user.
The following code:
Guid guid = Guid.NewGuid(); ShortGuid sguid1 = guid;
You will get this result:
FEx1sZbSD0ugmgMAF_RGHw b1754c14-d296-4b0f-a09a-030017f4461f
This is the code for the Encode and Decode method:
public static string Encode(Guid guid) { string encoded = Convert.ToBase64String(guid.ToByteArray()); encoded = encoded .Replace("/", "_") .Replace("+", "-"); return encoded.Substring(0, 22); } public static Guid Decode(string value) { value = value .Replace("_", "/") .Replace("-", "+"); byte[] buffer = Convert.FromBase64String(value + "=="); return new Guid(buffer); }
source share