Showing posts with label display name. Show all posts
Showing posts with label display name. Show all posts

February 20, 2014

SharePoint How to get SPUser from list item C#



How to get SPUser from list item, SharePoint list item get user, how to get created, modified, Author or Editor from sharepoint list, how to get LoginName or Email of User from list,

Well there is another way to get Web. EnsureUser(“User”); it returns SPUser object as well it adds user in site directly if do not already that web user, another way to get it write a function that return SPUser object,   

*Assuming that you are aware how to get SPWeb and List then List item,

SPUser oUserSubmittedBy = GetSPUser(oItem, “fieldDisplay Name”);

Here is the function body.



Code:
protected SPUser GetSPUser(SPListItem item, string user)

        {

            SPUser oUser = null;

            SPFieldUserValue userValue = new SPFieldUserValue(item.Web, Convert.ToString(item[user]));

            if (userValue != null)

            {

                oUser = userValue.User;

            }

            return oUser;

        }


And once you get object you can get Name, email and login name

oUserSubmittedBy.LoginName
oUserSubmittedBy.Name
oUserSubmittedBy.Email…. etc..



--
Regards,
Praveen Pandit

November 20, 2013

SharePoint PowerShell How to Rename Field or column name




PowerShell has ability to update every property that is available to edit in bulk and ofcourse in Sharepoint, Really it’s a awesome scripting language...

its simple just have SPWeb then SPList then its field and rename its Display name by using 'Title' property


 $w=Get-SPWeb –identity “http://serverurl/weburl”  
 $fld= $w.Lists[$spListName].Fields[“FieldName”]  
 $fld.Title = “Field New Name”  
 $fld.Update()  


You can simple user foreach loop for all lists or All sites to do so.

We cannot change its internal name if you wanna do so take backup of list delete specific column / field and recreate with new name.






Please share yours findings or issue if any on this.

--
Thanks for Visiting!
Praveen Pandit