Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
SPList resourceList = SiteProvisioningProvider.GetListReference(web, "Lists/list");
                foreach (SPFieldUserValue admin in adminCollection)
                {
                    SPListItem resourceItem = resourceList.Items.Add();
                    string name = admin.User.Name;
                    resourceItem["FirstName"] = name.Split(' ')[0].ToString();
                    resourceItem["Email"] = admin.User.Email;//null
                    resourceItem.Update();
                    web.SiteGroups["Engagement Administrator"].AddUser(admin.User);
                }
                resourceList.Update();

Above code is returning email and name of the user infomation. The same methos is called when i click some button in sharepoint site and also timer job calling the same method. But nly in the timer job i am not getting any email id for any user in any domain. This is happening is production environment not with QA/DEV. What will be the issue?
share|improve this question
    
your code run inside SPSecurity.RunWithElevatedPrivileges(delegate() { }); ?? and other thing is check in userprofile that email is added or not –  Vishal_Sharepoint Aug 27 '12 at 11:37
    
yep, email added properly.same code work every where except it get called from the timmer job. –  MarsMan Aug 27 '12 at 11:48

2 Answers 2

up vote 0 down vote accepted

you can find sharepoint all user from hidden list named "User Information List". and its url like this "siturl/_catalogs/users/simple.aspx". using this list you can fetch all email id of sharepoint users.

public string getEmail(string firstName,lastName)
{
string emailID = "";
 try
   {
     SPListItemCollection spListItemColl = Site.RootWeb.SiteUserInfoList.Items;
     foreach (SPListItem item in spListItemColl)
     {
         //Checking for first and last name
      if (item["FirstName"] != null && (firstName.ToUpper() == item["FirstName"].ToString().ToUpper()) && item["LastName"] != null && (lastName.ToUpper() == item["LastName"].ToString().ToUpper()) && item["EMail"] != null)
      {
  emailID = item["EMail"].ToString();
   break;
      }
   }
 }
catch (Exception ex)
{
throw ex;
}
return emailID;
}

you can also see this link might be helpful for you: http://zimmergren.net/technical/sharepoints-hidden-user-list-user-information-list

share|improve this answer

Hi please check this ans.

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/0a51a562-ccf3-48be-b502-ba6a443f05b7/

share|improve this answer
    
this post talking about the the current user. my issue is with all the users. –  MarsMan Aug 27 '12 at 12:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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