Get Mail ID from Active directory



SPUser object but if see we used EnsureUser method.  EnsureUser is predefined method it will check whether a user exist in the current site or not.
  If the user does not exist in the current site it will add the user to current site.
  SPFieldLookupValue, it’s predefined function.  It will grab the lookup ID and lookup value. In our example lookup value means user name “Sreehari, Inukoll”
using (SPSite siteCollection = new SPSite("http://"))
            {
                using (SPWeb web = siteCollection.RootWeb)
                {
                    SPList lstPOCreation = web.Lists["listofspusers"];
                    SPListItemCollection items = lstPOCreation.GetItems();
                    foreach (SPListItem item in items)
                    {
                        SPUser to_user = web.EnsureUser(new SPFieldLookupValue(item["userid"].ToString()).LookupValue);
                        item["email"] = to_user.Email.ToString();
                        item.Update ();
                        Console.WriteLine(item["ID"]);
                    }
                    Console.WriteLine("******* Please press any key to exist *******");
                    Console.ReadKey();
                }
                }
            }

Comments

Popular posts from this blog

what is Event Cache table in sharepoint

CAML Query syntax and options in SharePoint

Change anchor link url in sharepoint calender