Alec Tang

Professional Web Developer/ Web Designer

I build websites based on the latest web standards providing the best possible solution to your company

  • Home
  • About
  • Portfolio
  • Contact
  • Blog
Subscribe Feed

Getting SPUser from SPQuery programmatically

Posted by Alec on Wed, 03 Feb 2010, in ASP.NET C#   Sharepoint   

I needed to get SPUser object from doing a lookup using CAML query, so that I could get the user information such as email address, etc. To do that, this is the code that I used:

oList = web.Lists["Reviewers"];
SPQuery query = new SPQuery();
//do a lookup to the Reviewer list whose MosLevel2 and MosLevel3 are what being selected...
query.Query = "<Query><Where><And><Eq><FieldRef Name='MOSLevel2' /><Value Type='Lookup'>" + 
ddlMosLevel2.SelectedValue + "</Value></Eq><Eq><FieldRef Name='MOSLevel3' />
<Value Type='Lookup'>" + ddlMosLevel3.SelectedValue + "</Value></Eq></And></Where>
</Query>";
 SPListItemCollection result = oList.GetItems(query);
object oo = result[0]["Reviewer"];
SPFieldUserValue oReviewer = new SPFieldUserValue(web, oo.ToString());
SPUser uReviewer = oReviewer.User;
string strEmail = u.Email;
Comments Be the first to write a comment. Comment gets approved before publishing.

Post Your Comment

 
 
   

Search

 

Latest Posts

  • Website finally back up from Google's block
  • Sys.WebForms.PageRequestManagerParserErrorException
  • How Google treats Content Duplication
  • How to create HTML column in Sharepoint List View
  • How Sharepoint stores User Data
  • How to send email via Sharepoint
  • Malaysia Airlines launched iPhone Application: MHMobile
  • Intranet, the next big market
  • How to retrieve and update from a multi choice Checkboxlist ...
  • Auto Complete returns giant list of undefined

Categories

  • Browsers (1)
  • Projects (1)
  • Web Design (7)
  • Sharepoint (20)
  • Telerik (5)
  • Wordpress (1)
  • Internet (2)
  • SQL (5)
  • LINQ (3)
  • ASP.NET C# (33)
  • JavaScripts (3)
  • IIS (0)
  • Industry (1)
  • Tools (8)
  • SEO (5)

Archives

  • August 2010 (1)
  • May 2010 (1)
  • April 2010 (3)
  • March 2010 (5)
  • February 2010 (4)
  • January 2010 (11)
  • November 2009 (3)
  • October 2009 (1)
  • September 2009 (9)
  • August 2009 (3)
  • July 2009 (4)
  • June 2009 (1)
  • May 2009 (2)
  • April 2009 (8)
  • March 2009 (6)
  • February 2009 (2)
© Copyright 2009 Alec Tang. All Rights Reserved.
This site is conform to W3C Standard XHTML & CSS