Skip to main content
added 2 characters in body
Source Link
user3801
user3801

Context

I have a List<SPPrincipal> that is a mix of SPGroup, SPUser and AD Users.

Problem

I'm trying to find out how to determine if an SPPrincipal I have is an SPUser, SPGroup or an AD user.

Attempted solutions

Ive tried something like:

foreach (var principal in listOfPrincipals
{
  if (SPPrincipalprincipal is SPGroup) { //* do stuff */ }
}

But this does not appear to work.

Does anyone have any ideas about how to resolve this information ?

Update

After fiddling a bit I came to this solution that seems to work for SPGroup and SPUser

foreach (SPPrincipal subscriber in listOfSubscriberUsersAndGroups)
{
   var isGroup = subscriber is SPGroup;
   var isUser = subscriber is SPUser;
}

Here an SPGroup is found correctly, and SPUser is found correctly.

Update 2

The above actually works like it is supposed to. My mistake was that the SPPrincipal I was testing was actually a Domain-group, and not an SPGroup (red ears)

Context

I have a List<SPPrincipal> that is a mix of SPGroup, SPUser and AD Users.

Problem

I'm trying to find out how to determine if an SPPrincipal I have is an SPUser, SPGroup or an AD user.

Attempted solutions

Ive tried something like:

foreach (var principal in listOfPrincipals
{
  if (SPPrincipal is SPGroup) { //do stuff }
}

But this does not appear to work.

Does anyone have any ideas about how to resolve this information ?

Update

After fiddling a bit I came to this solution that seems to work for SPGroup and SPUser

foreach (SPPrincipal subscriber in listOfSubscriberUsersAndGroups)
{
   var isGroup = subscriber is SPGroup;
   var isUser = subscriber is SPUser;
}

Here an SPGroup is found correctly, and SPUser is found correctly.

Context

I have a List<SPPrincipal> that is a mix of SPGroup, SPUser and AD Users.

Problem

I'm trying to find out how to determine if an SPPrincipal I have is an SPUser, SPGroup or an AD user.

Attempted solutions

Ive tried something like:

foreach (var principal in listOfPrincipals
{
  if (principal is SPGroup) { /* do stuff */ }
}

But this does not appear to work.

Does anyone have any ideas about how to resolve this information ?

Update

After fiddling a bit I came to this solution that seems to work for SPGroup and SPUser

foreach (SPPrincipal subscriber in listOfSubscriberUsersAndGroups)
{
   var isGroup = subscriber is SPGroup;
   var isUser = subscriber is SPUser;
}

Here an SPGroup is found correctly, and SPUser is found correctly.

Update 2

The above actually works like it is supposed to. My mistake was that the SPPrincipal I was testing was actually a Domain-group, and not an SPGroup (red ears)

added 348 characters in body
Source Link
user3801
user3801

Context

I have a List<SPPrincipal> that is a mix of SPGroup, SPUser and AD Users.

Problem

I'm trying to find out how to determine if an SPPrincipal I have is an SPUser, SPGroup or an AD user.

Attempted solutions

Ive tried something like:

foreach (var principal in listOfPrincipals
{
  if (SPPrincipal is SPGroup) { //do stuff }
}

But this does not appear to work.

Does anyone have any ideas about how to resolve this information ?

Update

After fiddling a bit I came to this solution that seems to work for SPGroup and SPUser

foreach (SPPrincipal subscriber in listOfSubscriberUsersAndGroups)
{
   var isGroup = subscriber is SPGroup;
   var isUser = subscriber is SPUser;
}

Here an SPGroup is found correctly, and SPUser is found correctly.

Context

I have a List<SPPrincipal> that is a mix of SPGroup, SPUser and AD Users.

Problem

I'm trying to find out how to determine if an SPPrincipal I have is an SPUser, SPGroup or an AD user.

Attempted solutions

Ive tried something like:

foreach (var principal in listOfPrincipals
{
  if (SPPrincipal is SPGroup) { //do stuff }
}

But this does not appear to work.

Does anyone have any ideas about how to resolve this information ?

Context

I have a List<SPPrincipal> that is a mix of SPGroup, SPUser and AD Users.

Problem

I'm trying to find out how to determine if an SPPrincipal I have is an SPUser, SPGroup or an AD user.

Attempted solutions

Ive tried something like:

foreach (var principal in listOfPrincipals
{
  if (SPPrincipal is SPGroup) { //do stuff }
}

But this does not appear to work.

Does anyone have any ideas about how to resolve this information ?

Update

After fiddling a bit I came to this solution that seems to work for SPGroup and SPUser

foreach (SPPrincipal subscriber in listOfSubscriberUsersAndGroups)
{
   var isGroup = subscriber is SPGroup;
   var isUser = subscriber is SPUser;
}

Here an SPGroup is found correctly, and SPUser is found correctly.

Source Link
user3801
user3801

Determine if SPPrincipal is SPUser, SPGroup or AD User

Context

I have a List<SPPrincipal> that is a mix of SPGroup, SPUser and AD Users.

Problem

I'm trying to find out how to determine if an SPPrincipal I have is an SPUser, SPGroup or an AD user.

Attempted solutions

Ive tried something like:

foreach (var principal in listOfPrincipals
{
  if (SPPrincipal is SPGroup) { //do stuff }
}

But this does not appear to work.

Does anyone have any ideas about how to resolve this information ?