Tag Info

New answers tagged


Sorry for the bump of an old post, but if someone is interested in doing this, there is another option if security is not your main concern Audiences are used to show web parts for only specific people. If someone knows how to navigate SharePoint, they can still get to that content, but it takes away the easy option. You would create a web part that ...


Try this SPUserCollection users=web.SiteUsers; SPUser user=users.GetByID(31); SPweb.User return only users who are directly set as user on the web, if someone have access to web because he is in the particular group, this user cannot be found. SPweb.SiteUsers return all users


I think you may be missing the following line: web.AllowUnsafeUpdates = true; Since you are ensuring the user is part of the website and if not, it adds that user to the site, then you need to allow unsafeupdates. Your code should be: web.AllowUnsafeUpdates = true; SPUser user = web.EnsureUser(@"Domain\LoginName"); //do more code stuff ...


I suggest check it in PowerShell $web = get-spweb $weburl; $web.siteusers | ft UserLogin, Id; Then try to get that specific user by id $user = $web.siteusers.getbyid(31); $user; If this works in PowerShell, it should work in your managed code. SPUser approver = web.SiteUsers.GetById(31); NOTE: One thing to be aware of is that a users Id will change ...


If you have the user's email address, give this method a try: SPUser approver = web.SiteUsers.GetByEmail("approver@domain.se");


Try any of the below: web.EnsureUser(@"domain\loginname");//This will add user to site if not already added. //Best to use this if you have the login name and //user is already added. web.SiteUsers.GetByID(31); //This will get you the user by id.

Top 50 recent answers are included