MOSS Query

Found an amazing tool to build queries for MOSS.

http://www.codeplex.com/SharePointSearchServ/

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Getting a User's Details from a Sharepoint List

Soemtimes we need to find the identity or other details about a user within Sharepoint from a list column. As a example, to find a user's login name from the 'Created By' column.

you may have looked at the values stored in this or similar columns & noticed that the name is stored in the form of id#loginname. You could manipulate the string to get the values, but there is a ready made function to let us do this and more - SPFieldUserValue.

The function provides 4 properties...

LookupId - the id before the #
LookupValue - the text displayed in the column
SIPAddress - the SIP (Messenger) address used for presence
User - a SPUser object

By using the last property we can quickly gain access to all of the SPUser properties. The code below give a quick example

//we assume we have already referenced a list / web / site and the example is getting the first item...

SPListItem item = mySPList.Items[0];

SPFieldUserValue userVal = new SPFieldUserValue(item.ParentList.ParentWeb, item["Created By"].ToString());

string userLoginName = user.User.LoginName;

string userDisplayName = user.User.Name;

//etc

An example of useage is programatically assigning workflow tasks to a document creator

Currently rated 2.0 by 1 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

 

Dilbert of the day