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

[code:c#]

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

[/code]

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

Comments

June 15. 2010 13:19

Lorraine Cerise

I don't believe this! :-)

Lorraine Cerise

August 7. 2010 01:19

elephant in the sand

Let us look for the stolen time,IT'S GOOD POST,<a href="http://www.watchestoo.com/index.php?main_page=wordpress&p=250">breitling superocean 2010</a>

elephant in the sand

August 13. 2010 11:10

Marchelle Fauset

Wonderful post. I wish more folks had simple and direct stuff similar to the ones you have. Kudos :)

Marchelle Fauset

August 14. 2010 00:42

Messenger Bags

I need a new Messenger Bag

Messenger Bags

August 17. 2010 14:16

Heath Bigusiak

I am pretty glad to discover this insight that I had been looking for some time. This made me quite thrilled... This site has provided us fairly helpful content. Cheers

Heath Bigusiak

August 17. 2010 14:40

vigrx

your site layout is very good

vigrx

August 17. 2010 14:41

vigrx

your site layout is very good

vigrx

August 19. 2010 04:02

Bradley Farish

Cool, there are really some good points on this post a number of my visitors could find this relevant, I will post a link, thanks.

Bradley Farish

August 26. 2010 23:12

Fashion Replica Handbags

2010 is the beginning of a new decade of the mark and thus represents an awakening of the class. The economy is not exactly where everyone wants practicality is as important as distinctive. This means that fewer people are splurging on Fashion Replica Handbags, haute couture $ 10,000 may be used only once, instead of in bags that are more versatile to invest.

Fashion Replica Handbags

August 26. 2010 23:13

Rolland Julien

I ever watched great stories about doing small time but make great time. I was surprised, so I ignored them. But it is my fault, so you must not capable and follow me to do that. When the time was changed the ecosystem will be changed too. But one can’t be changed, it is the changes itself. Why? No more to explain that. Getting the most valuable person like you is my future lucky. The best time to do that is with my brain. Offline time can be bored, so why don’t you use online time to become rich together? Vacation can be good one; especially we hope that after reaching success, time we spent can be substituted with great time for vacation. I am sure that you are capable in doing that, so great people will meet great time for spending time. Have a nice travel with chosen one. Really wonderful one!

Rolland Julien

August 27. 2010 14:09

Myrtle Beach Real Estate

ive been looking for information similar to this

Myrtle Beach Real Estate

August 28. 2010 00:08

Serafina Gillians

If I might --perhaps you should consider adding a few images. I dont mean to disrespect what youve said; its very enlightening, indeed. However, I think would respond to it more positively if they could be something tangible to your ideas. Keep it up, but put a little more into it next time

Serafina Gillians

August 29. 2010 17:05

student driver magnetic sign

Youre so awesome, man! I cant believe I missed this blog for so long. Its just great stuff all round. Your design, man...too amazing! I cant wait to read what youve got next. I love everything that youre saying and want more, more, MORE! Keep this up, man! Its just too good.

student driver magnetic sign

August 30. 2010 15:35

bail bonds

I hope you never stop! This is one of the best blogs Ive ever read. Youve got some mad skill here, man. I just hope that you dont lose your style because youre definitely one of the coolest bloggers out there. Please keep it up because the internet needs someone like you spreading the word.

bail bonds

August 31. 2010 23:57

Baby Gifts, New Baby Gifts

One of the more impressive blogs Ive seen. Thanks so much for keeping the internet classy for a change. Youve got style, class, bravado. I mean it. Please keep it up because without the internet is definitely lacking in intelligence.

Baby Gifts, New Baby Gifts

September 1. 2010 09:24

Christina Hendricks Pictures

This really answered my problem, thank you!

Christina Hendricks Pictures

September 1. 2010 09:28

Eugene

Have you considered adding some videos to your article? I think it will really enhance everyone's understanding.

Eugene

September 1. 2010 09:59

Washington

Oh man. This blog is amazing! How do you make it look like this ?

Washington

September 1. 2010 10:08

starcraft 2 hacks

Wow! This blog is amazing! How did you make it look this good !?

starcraft 2 hacks

September 1. 2010 11:59

Ask the Doctor

Just discovered this blog through Google, what a way to brighten up my week!

Ask the Doctor

September 1. 2010 12:00

Stock Picks

Wow! This website is cool. How can I make it look like this ?

Stock Picks

September 1. 2010 12:00

make money help

I'm getting a javascript error, is anyone else?

make money help

September 1. 2010 20:48

Nude Chat

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post

Nude Chat

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



 

Dilbert of the day