0

I want to get the group of the connected user

The problem is when I connect to sharepoint by any account, the current logged in account in my workflow got by Web.CurrentUser is always SHAREPOINT\System.

What I want is the real connected user to check a group of this user:

public static bool IsUserMemberOfGroup(string groupName)
{
    using(SPSite site = new SPSite(sitename)){
        using(SPWeb oweb = site.OpenWeb()){
            SPUser user = oweb.CurrentUser;
            if(user.Groups["groupename"].loginName == groupName){
                //do something
            }
        }
    }
}
3

The code within a workflow is executed by the system account (farm account). Thus, when you try to get the user that way, you will only get the system account. You need to retrieve the user from the properties of the workflow instance. See Get the current user interacting with a site workflow for info on how.

  • thanks at first but what i'm doing is i got the user from workflow SPWorkflowActivationProperties.Web.CurrentUser but the same problem – ezzaam May 20 '14 at 16:14
  • The second answer (the one that isn't marked as the answer) has two ways you can get this in your code. – John Chapman May 20 '14 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.