Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

SPUser email details

  Asked By: Korey    Date: Nov 22    Category: Sharepoint    Views: 2950

Our SPS installation is configured with Active Directory.
User are added to SPS as AD groups. Email for users is configured in AD.

We are using the SPUser's email method to get the user's email ID.
But this method retrives email ids only for some users. Others have a null value.

I am not sure why this happens. Any ideas?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Stephon Valentine     Answered On: Nov 22

You should 'refresh' the data in A/D into SPS using
the SPS Profile Database (Site Settings, Manager
profile database). You can also set it to automatic
refresh once in a while.

Then you can use the following code to approach the
UserProfiles (eg to retrieve for the current user) in
your webpart:

// extract the uri from the current site
SPWeb spc = SPControl.GetContextWeb(Context);
Uri uri1 = new Uri(spc.Site.RootWeb.Url);

// initializing GlobalAdmin
SPGlobalAdmin globaladmin = new SPGlobalAdmin();

// getting this Virtual Server
SPVirtualServer virtualserver =
globaladmin.OpenVirtualServer(uri1);

// getting the root url
string sRootUrl = virtualserver.Url.ToString();
Microsoft.SharePoint.Portal.Topology.TopologyManager
tm = new
Microsoft.SharePoint.Portal.Topology.TopologyManager();
Microsoft.SharePoint.Portal.Topology.PortalSite ps =
tm.PortalSites[new Uri(sRootUrl)];
PortalContext pc = PortalApplication.GetContext(ps);

//initialize user  profile config manager object
Microsoft.SharePoint.Portal.UserProfiles.UserProfileManager
upm = new
Microsoft.SharePoint.Portal.UserProfiles.UserProfileManager(pc);
UserProfile userProfile =
upm.GetUserProfile(spc.CurrentUser.ToString());

string sName =
userProfile["PreferredName"].ToString();
string sEmail = userProfile["WorkEmail"].ToString();
string sID = spc.CurrentUser.ID.ToString();

spc = null;
globaladmin = null;
virtualserver = null;
tm = null;
ps = null;
upm = null;
userProfile = null;

As you can see the email  address is the 'WorkEmail'
property in the UserProfile. If you click on the
'Manage Profile Database' the last option 'View
profile properties' you get an overview of ALL
properties.

 
Answer #2    Answered By: Leif Cardenas     Answered On: Nov 22

At present in our project we are not planning to import data to the SPS server.
So, I was looking at retriving the email  just with the SPUser data which is retrived from the AD.

 
Didn't find what you were looking for? Find more on SPUser email details Or get search suggestion and latest updates.




Tagged: