Home
Manage Your Code
Snippet: Get current user in workflow sharepoint context (C#)
Title: Get current user in workflow sharepoint context Language: C#
Description: Get current user in workflow sharepoint context Views: 1574
Author: Bin Ku Date Added: 2/15/2011
Copy Code  
1/// <summary>
2        /// Get current user in workflow sharepoint context
3        /// </summary>
4        /// <param name="workflowProperties"></param>
5        /// <returns></returns>
6        public static SPUser GetCurrentUserInWorkflow(Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties workflowProperties)
7        {
8            string ModifiedbyUserName = Convert.ToString(workflowProperties.Item.GetFormattedValue("Modified By"));
9            string[] strChar = { "ID=" };
10
11            string[] strChars = ModifiedbyUserName.Split(strChar, StringSplitOptions.None);
12
13            Int32 iUserID = Convert.ToInt32(strChars[1].Substring(0, strChars[1].IndexOf("\"")));
14            
15            SPUserCollection usersInSite = workflowProperties.Web.SiteUsers;
16            int countUsers = usersInSite.Count;
17            for (int iCnt = 0; iCnt <= countUsers - 1; iCnt++)
18            {
19                if (usersInSite[iCnt].ID == iUserID)
20                {
21                    return workflowProperties.Web.SiteUsers[iCnt];                    
22                }
23            }
24            return null;
25        }
Notes
http://www.sharepointkings.com/2008/08/how-to-get-currently-logged-in-user-in.html