2

I have a piece of code which gets the email address of a SPUser object. The email property is empty. Where I can fill the email address of this user? Is it in SharePoint or somewhere in AD? I dont have a sync connection to AD!

SPFieldUser userField = (SPFieldUser)currentItem.Fields.GetField(Constants.Fields.FIELD_CLIENT);
            SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(Convert.ToString(currentItem[Constants.Fields.FIELD_CLIENT]));
            SPUser assignedToUser = fieldValue.User;


string clientEmail = assignedToUser.Email;

// dosomething

2 Answers 2

2

1.Assuming you do not have User Profiles Synchronized , there are no email address for the users You need to create a UserProfile Synchronization Service ,so that all the users are sync/imported to sharepoint. Later you can user profile code and get the relevant users information.

OR

2.ELSE If you are not using/configuring User Profile Service anytime .You will need to have your design changed (where a user enters his/her email id) or some other mechanism.

1

You will need to actually request the user profile for that user so you can read all the properties for that user (including email). This question has some samples of how to do that in code: How to get user profile property value when privacy for property set to "Private" (only me)

1
  • Since there is no User Profile servive . How will this work ?
    – Nikhil J
    Mar 21, 2014 at 15:59

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.