Tag Info

Hot answers tagged


Are you sure that you provided correct code snippet? if it is true, the VS should throw this exception: 'Microsoft.SharePoint.SPPrincipal' is a 'type' but is used like a 'variable' and break build action. You should use principal variable instead of SPPrincipal class: foreach (var principal in listOfPrincipals) { if (principal is SPGroup) { //do stuff } } ...


Have you tried running the old STSADM way of migrating users - like the following script. STSADM –o migrateuser –oldlogin MYDOMAIN\old –newlogin MYDOMAIN\new –ignoresidhistory There might be orphaned users which doesn't get handled correct. You can clean up these orphans using the following script: # Clean up accounts that is not imported correctly # ...


After further investigating I found that Notes is a property of the SPUser class. Thus, following would work: var spRole = new SPRoleAssignment("domain\\name", "abc@xyz.com", "name", "notes for user"); var spUser = (SPUser)spRole.Member; var notes = spUser.Notes;


According to MSDN it's a getter property, so you can not set it. A similar question was asked a few years back. However according to the answer: you can set a service account as owner and specify that only the owner can add members (AllowMembersEditMembership = false) if that is why you're asking.


public List<String> GetADGroups() { List<String> result = new List<String>(); PrincipalContext ctx = new PrincipalContext(ContextType.Domain, ServerName, UserName, Password); GroupPrincipal findAllGroups = new GroupPrincipal(ctx, "*"); PrincipalSearcher ps = new PrincipalSearcher(findAllGroups); foreach (Principal group ...


It looks like there is not simpler solution that this one : public static SPPrincipal GetPrincipal(SPWeb web, int principalID, string principalName) { return web.AllUsers.Cast<SPPrincipal>().SingleOrDefault(u => u.ID == principalID) ?? web.SiteGroups.Cast<SPPrincipal>().SingleOrDefault(g => g.ID == principalID); } Feel free ...


I've done this by querying against the web.SiteGroups collection and the web.AllUsers collection, just as you have done, however I didn't cast. I instantiated an SPPrincipal to null and then set it equal to the SPGroup or SPUser before returning it. Here's an example using iteration rather than Linq: private SPPrincipal GetPrincipal(SPSite spsSite, ...

Only top voted, non community-wiki answers of a minimum length are eligible