Extension method to find root Parent Workflow of current activity

Below is an extension method  to find root Parent Workflow of current activity
  /// <summary>
  /// Get root Parent Workflow of current activity
  /// <param name=”activity”></param>
  /// <returns></returns>
  public static Activity FindRootWorkflow(this Activity activity)
  {
   List<string> list = new List<string>();
   Activity act = activity;
   while (act != null)
   {
    if (act.Parent==null)
    {
     return act;
    }
    act = act.Parent;
   }
   return null;
  }
 
It was  asked in MS Connect Suggestion “Activity to access Parent workflow or Root Workflow
 

 

Advertisements