Solved

sharepoint 2010 userproperty "SPS-HireDate" is not working

Posted on 2011-02-28
2
1,355 Views
Last Modified: 2013-11-25
Hi,
I am trying to access "SPS-hireDate" property from code.

But I can't able to open my webpart because it is showing error.



                         if (userinfo["SPS-HireDate"] != null)
                         {
                             lblOutput.Text += "<tr height='20px'><td style='padding-left:10px;color:#000000;font-weight:bold;font-style:italic;font-size:11px;font-family:Arial, Helvetica, sans-serif;'>" + userinfo["SPS-HireDate"].ToString() + "</td></tr>";

                         }
                     
 i am attaching all code for this webpart
Error--SPS-HireDate.png
UserInfo.cs
0
Comment
Question by:smskareem
2 Comments
 
LVL 4

Accepted Solution

by:
Pstry earned 125 total points
ID: 35007134
The 'SPS-HireDate' field does not exist in UserInfo list.

Use user profiles instead:

ctx = SPServiceContext.GetContext(SPContext.Current.Site);
manager = new UserProfileManager(ctx);
profile = manager.GetUserProfile(web.CurrentUser.LoginName);
Console.WriteLine(profile["SPS-HireDate"].ToString());  // Check for NULL first !
// or, better:
Console.WriteLine(profile[PropertyConstants.HireDate].ToString());  // Check for NULL first !
   
0
 

Author Closing Comment

by:smskareem
ID: 35015001
Thanks a lot !
Very helpful and clear.

i need 1 more thing ...like in given url
http://msdn.microsoft.com/en-us/library/ms519896.aspx

using (SPSite site = new SPSite("http://servername"))

So what is actual "server name"?

is it a url of Central Admin or url of any site or only "computer name"?
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cloud / Hybrid file storage & collaboration 5 83
Please explain "Multi-Tenant Services" 5 99
SharePoint Online Security 5 81
SharePoint 2013 Site Replacement 6 33
If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question