Tag Info

Hot answers tagged

17

It sounds like you've gotten two concepts slightly muddled. There are three entities that are important here: A field/column on a list (SPField and its derivatives, including SPFieldUser) A row of data (SPListItem) A data item (string, SPUser, etc. according to field type) Each row of data (List Item) has a data item for each of the fields, but fields ...


7

To check if the Current User is system account you can use if (web.CurrentUser.ID == web.Site.SystemAccount.ID) SystemAccount is a property of SPSite object which gets the System Account of the site collection


6

In IE (version > 6) SignOut.aspx uses ClearAuthenticationCache as a client side command. This does not work for Firefox. I found this example on StackOverflow that might work for you http://stackoverflow.com/questions/31326/is-there-a-browser-equivalent-to-ies-clearauthenticationcache


5

SPContext.Current.Web.CurrentUser.ID == SPContext.Current.Site.SystemAccount.ID This method is suitable?


5

You need to have user's first and last name in SharePoint User Profile Service Application in order to see 'firstname lastname'. Try modifying User Profile of your test user: add first and last name. Then log out and back in and you should see the correct name. If that works, update other users as well (by setting up user profile synchronization).


4

SPWeb.Users.GetByEmail() and SPWeb.Users.GetById() is only going to return the users that have logged in to your site. Try the method SPWeb.EnsureUser(). MSDN says the following: Checks whether the specified logon name belongs to a valid user of the website, and if the logon name does not already exist, adds it to the website.


4

You can retrieve the system account by SPSite property SPContext.Current.Site.SystemAccount Basicaly EnsureUser method uses logon name (Domain\User_Alias) of the user.


4

The SPUser object (SPContext.Current.Web.CurrentUser) does have a Name property, but it may not be filled out. If not, you may need to resort to going against the user profile ( http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofile(v=office.12).aspx ), but that is only available in Server (not Foundation).


4

You can compare the token value of the account to determine if it is equal to the one of the system account. Note that in the following you get the SPSite object under elevated privileges and that comparing tokens only works when the actual account in SharePoint is already listed as the system account. SPUser user = <<your code here>> SPSite ...


3

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 } } ...


3

if you do not use user profile service, you can go to site actions -> site permissioms. There are users and groups that have access to your site. In this list you can click on a user name and see it's details. In ribbon on details view you can click on Edit button and set Name property of this user. after this you can retrieve it by SPUser.Name


3

Workflows do not have an SPContext so SPContext.Current will always be null. In order to do what you appear to be trying to do, you may have to open the site once as the AppPool account to get the user token then release the site. Then open it again using the token like you are doing now. Something like this : SPUserToken token = null; using (SPSite ...


3

As far as I know you will have to parse the XML. Its very easy to do string xml = @"<pc:Person xmlns:pc=""http://schemas.microsoft.com/office/infopath/2007/PartnerControls""> <pc:DisplayName>John Dodo</pc:DisplayName> <pc:AccountId>DOMAIN\john.dodo</pc:AccountId> ...


3

I have been through the same scenario as you described (also with the Quest tool). We cleaned it up by running the stsadm -o migrateuser command. This will migrate all of the content associated with the old account to the new account and remove any references of the old account in the site collection. It needs to be run once per user, per farm.


3

You should just be able to use SPWeb.EnsureUser. It understands claims. For example (from Tyler Holmes): SPUser spUser = web.EnsureUser(string.Format("i:0#.f|providerName|{0}", fbaUser.UserName)); spUser.Name = "FriendlyName"; spUser.Update();


3

try this: SPUser creator = new SPFieldUserValue(web, this.ListItem["Author"].ToString()).User; SPUser currentUser = SPContext.Current.Web.CurrentUser; CurrentUserIsExpertiseCreator = creator.Name.Equals(currentUser.Name); instead of comparing the spuser object compare against the name (string) or ...


3

To my knowledge there is no direct way to retrieve this easily. Enabling Audit logs is not a good call as it creates a lot of data for nothing, and particularly it is per Site Collection, which leaves the question : "do you enable this for all site collections?" - you are in for a tremendous amount of information - weight that carefully. In the past we've ...


3

You need to include the Domain name in EnsureUser - Domain\Username


3

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


2

You can assign the SPUser object directly to the field: SPUser user = web.SiteUsers["domain\\username"]; item["MyCustomField"] = user;


2

To summarize comments. SpWeb.EnsureUser method will throw an exception if user account doesn't exist in Active Directory or if it is disabled. Code provided in question could look like this (in foreach loop): try { $spUser = $web.EnsureUser($user) Write-Host "Adding " $spUser $web.SiteGroups[$spGroup].AddUser($spUser) Write-Host $user " ...


2

i guess you are looking for some api to resolve inputs. try this utility method: Microsoft.SharePoint.Utilities.SPUtility.ResolvePrincipal it will return a SPPrincipal object, witch contains a "LoginName" property. then you can use SPWeb.EnsureUser(loginName) to get a SPUser object. more infomation about this method: ...


2

The empty Guid here actually is not concerning. The SiteSubscriptionId will always be a blank Guid unless you have multi-tenancy enabled in your environment. Enabling Multi Tenant Support in SharePoint 2010 You may need to add permission for your user on the User Profile Service Application. In Configure User Profile sync connections they were trying to ...


2

There isn't any method or way you can find out last modified date of permission level for a user or group in SharePoint 2007 or 2010 at the moment unless there's a hack to find out but I think it will be rare, why you need to know it tho. Hope it helps.


2

If your person field is of type User or group with multiple values allowed, then its value in code is represented by SPFieldUserValueCollection class. Below is my code example. This is an extension method, which takes SPListItem and Guid of field to convert it to array of SPUser. You can chage Guid to the name of the field if you need to: public static ...


2

SPFieldUserValueCollection userVals = (SPFieldUserValueCollection)item["UserName"]; foreach (SPFieldUserValue userVal in userVals) { // your code SPUser user = userVal.User; } Hope it helps..


2

I have the same error. I noticed that the error occurs when the username has "." like in your screenshot. To be safe, you need to get the encoded claim value for the user and pass that into the EnsureUser method. Look these articles: First; Second. Or you can just add i:0#.f|myprovider| to the username so it looks like i:0#.f|myprovider|myuser and pass ...


2

SPUser.Groups returns a collection of SPGroups which the user is a member. Here is the documentation link


2

Try this: string userName = String.Empty; SPClaimProviderManager mgr = SPClaimProviderManager.Local; if(mgr != null) { userName = mgr.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName).Value; }


2

Instead of creating a new SPFieldUserValue find the one in the SPFieldValueCollection you want to remove like this: private static void DeleteUserFromList(SPUser userDeleted, string fieldName, SPListItem item, SPWeb sPWeb) { SPFieldUserValueCollection Users = (SPFieldUserValueCollection)item[fieldName]; SPFieldUserValue DeletedUserValue = ...



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