0

I am building a simple web part that needs the image that is used from the MySite and the First and Last name of the site owner. I know how to get the current user, I need the name. I am also having trouble getting the information off of the MySite. Any information on how to et any of these would be great.

I am getting the site:

string currentUser = SPContext.Current.Web.CurrentUser.ToString();
        using (SPSite ospSite = new SPSite("http://devchrisl01:14768/personal/"+ currentUser + ""))
        {
            //cant get the stuff
            ServerContext context = ServerContext.Current;
            UserProfileManager profilmanager = new UserProfileManager(context);
            UserProfile profile = profilmanager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);


        } 

The code I have found to use seems to not be working for me. I am getting reference erros for ServerContext and UserProfileManager. I do not seem to have these assemblies availible on my machine, or I am not using the right using reference.

[Edit]
I figured I was not using the right dll, so after little research I found the missing piece as far as getting the references correct. I am still looking for how to ge tthe Image and the Fist/Last name of the site owner. Any help would be great.

Thanks Again.

Thank you.

1 Answer 1

3

You should be able to get user information from the SiteUserInfoList rather than going directly to the MySite:

SPList myList = SPContext.Current.Web.SiteUserInfoList;

SPQuery query = new SPQuery { Query = string.Format("<Where><Eq><FieldRef Name='Name' /><Value Type='Text' >{0}</Value></Eq></Where>", SPContext.Current.Web.CurrentUser.LoginName) };
SPListItemCollection entries = myList.GetItems(query);
if (entries == null || entries.Count == 0)
    throw new Exception("User Not Found!");

Then to access the properties you can just pass the name of the property like this:

String firstname = entries[0]["FirstName"];

You will be interested in the FirstName, LastName and Picture properties, but you can also query the following properties:

Display Name        Type            Name

Content Type ID     ContentTypeId   ContentTypeId
Name                Text            Title
Approver Comments   Note            _ModerationComments
File Type           Text            File_x0020_Type
Account             Text            Name
E-Mail              Text            EMail
About Me            Note            Notes
SIP Address         Text            SipAddress
Locale              Integer         Locale
Calendar Type       Integer         CalendarType
AdjustHijriDays     Integer         AdjustHijriDays
TimeZone            Integer         TimeZone
Time Format         Boolean         Time24
Alt Calendar Type   Integer         AltCalendarType
CalendarView Options Integer        CalendarViewOptions
WorkDays            Integer         WorkDays
WorkDay StartHour   Integer         WorkDayStartHour
WorkDay EndHour     Integer         WorkDayEndHour
Is Site Admin       Boolean         IsSiteAdmin
Deleted             Boolean         Deleted
Picture             URL             Picture
Department          Text            Department
Job Title           Text            JobTitle
Is Active           Boolean         IsActive
Report To           User            Report_x0020_To
ID                  Counter         ID
Content Type        Text            ContentType
Modified            DateTime        Modified
Created             DateTime        Created
Created By          User            Author
Modified By         User            Editor
Has Copy Destinations Boolean       _HasCopyDestinations
Copy Source         Text            _CopySource
owshiddenversion    Integer         owshiddenversion
Workflow Version    Integer         WorkflowVersion
UI Version          Integer         _UIVersion
Version             Text            _UIVersionString
Attachments         Attachments     Attachments
Approval Status     ModStat         _ModerationStatus
Edit                Computed        Edit
Name                Computed        LinkTitleNoMenu
Title               Computed        LinkTitle
Select              Computed        SelectTitle
Instance ID         Integer         InstanceID
Order               Number          Order
GUID                Guid            GUID
Workflow Instance ID Guid           WorkflowInstanceID
URL Path            Lookup          FileRef
Path                Lookup          FileDirRef
Modified            Lookup          Last_x0020_Modified
Created             Lookup          Created_x0020_Date
Item Type           Lookup          FSObjType
Effective Permissions Mask Computed PermMask
Name                File            FileLeafRef
Unique Id           Lookup          UniqueId
ProgId              Lookup          ProgId
ScopeId             Lookup          ScopeId
HTML File Type      Computed        HTML_x0020_File_x0020_Type
Edit Menu Table Start Computed      _EditMenuTableStart
Edit Menu Table End Computed        _EditMenuTableEnd
Name                Computed        LinkFilenameNoMenu
Name                Computed        LinkFilename
Type                Computed        DocIcon
Server Relative URL Computed        ServerUrl
Encoded Absolute URL Computed       EncodedAbsUrl
File Name           Computed        BaseName
Property Bag        Lookup          MetaInfo
Level               Integer         _Level
Is Current Version  Boolean         _IsCurrentVersion
Group               Computed        GroupLink
Edit                Computed        GroupEdit
Name                Computed        ImnName
Picture             Computed        PictureDisp
Name                Computed        NameWithPicture
Name                Computed        NameWithPictureAndDetails
Edit                Computed        EditUser
Selection Checkbox  Computed        UserSelection
Content Type        Computed        ContentTypeDisp

The above table comes from: http://www.idocs.info/index.php/2010/08/sharepoint-designer-user-information-list-metadata-in-a-workflow/

3
  • Wow this is great thank you. i have started messing with it to see what I can get, but I think this is it. Your awesome!!
    – lazoDev
    Commented Mar 5, 2012 at 18:58
  • I am getting an error when I try to run the FirstName field. Also, it is not in the list. I am able to get the Picture URL no problem which is great. The only name I am able to pull off of this is the account name which is nice but not what I need. Any Ideas?
    – lazoDev
    Commented Mar 6, 2012 at 15:51
  • This is spot on - just saved me a LOT of messing around - thanks @theChrisKent. OP - consider marking answer as correct if that's the case. Commented Sep 13, 2012 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.