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


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

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

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

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

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

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

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

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

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

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

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

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

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

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


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


2

From what I could gather last time the issue occurred, this happens because SharePoint runs code on different threads and consequently can lock down items, users, just about anything. This happened to us when we were creating lots of folders and sub-folders in a multiple lists in quick succession. We could not find anything that worked after days of ...


1

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


1

Found Solution.. public static string FindPermissionLevelForUser(string loginname, string strSite) { string strValue = string.Empty; try { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(strSite)) { using (SPWeb web = ...


1

Getting Permission levels for a site Adding or Removing Permissions for a user or group Custom permission levels If you go through above links, I am pretty sure you will figure out code you need for what you're trying to do. Hope it helps.


1

If a user is deleted this method doesn't work as the Set-SPUser is used to: Configures properties on an existing user. (Technet - Set-SPUser) But if your user is deleted from SharePoint, but do exist in Active Directory you can add the user using New-SPUser: New-SPUser –UserAlias "AD\JoDo" –displayname "John Doe" –web $Web.Url -Group "GroupName"


1

To modify the login name of an User I used the SPFarm object. The code looks simple like this: Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite elevatedSite = new SPSite(url)) { using (SPWeb web = elevatedSite.OpenWeb()) { ...


1

AD users don't exist on SharePoint until something causes SharePoint to know about them (e.g. an explicit permission setting, the user has logged in, etc). Try using SPWeb.EnsureUser(string userlogonname) - it will create the user within SharePoint if it doesn't already exist, and return the SPUser object.


1

String UserName= “UserNameGoesHere”; SPUser oUser= SPWeb.EnsureUser(UserName); treenode.SelectedNode.Nodes.Add(oUser.Name); Where “UserNameGoesHere” you can change that to a varible as you loop through each string. or from msdn SPSite oSiteCollection = SPContext.Current.Site; using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"]) { ...


1

The sorting of Lookup columns (and a SPFieldUser is just a lookup column into the User Information List) depends on the LookupField of the lookup column. If you define your User field to display as one of the Name columns then the sorting of your Query should by the display name of the user.


1

ok, im presuming that you are creating the list using xml and not querying in .cs? whats the full code and are you doing it like this? <Query> <OrderBy> <FieldRef Name="SomeUserField"/> </OrderBy> </Query> You dont need to add in ascending = true as by default it is ascending. You only need to use it if you ...



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