Generate Unique ID in Custom Module

The GUID class defined in the .NET Framework class library provides functionality to generate unique id. It will be return collection character as like alpha and number.

In this topic about take GUID with random number and datetime for custom generate unique id. The unique id will be using for assign table unique id or access collections.

The following code return a custom unique id: 

  1. /// <summary>  
  2.   /// GenerateUniqueId Custom Unique ID  
  3.   /// </summary>  
  4.   /// <returns>Unique ID(GUID + Random + DateTime)</returns>  
  5.   public string GenerateUniqueId()  
  6.   {  
  7.       string strAcid = "";  
  8.       string strUniqueID = "";  
  9.   
  10.       strUniqueID = Guid.NewGuid().ToString();  
  11.       strUniqueID = strUniqueID.Replace("-""");  
  12.   
  13.       Random random = new Random();  
  14.       strAcid = random.Next(100000, 999999).ToString() + "-";  
  15.   
  16.       strAcid = strAcid + DateTime.Today.ToString("ddMMyy") + "-";  
  17.   
  18.       strAcid = strAcid + strUniqueID.Substring(0, 6) + "-";  
  19.   
  20.       strAcid = strAcid + strUniqueID.Substring(6, 6) + "-";  
  21.   
  22.       strAcid = strAcid + DateTime.Now.ToString("mmssff");  
  23.   
  24.       return strAcid;  
  25.   }  

 

Generate ID