Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I know that;

SPWeb.EnsureUser(string loginName);

can be used to add Domain Users with login name, to the site users. But i have a list with only email addresses. How can i add these people to site users?

Is there anyway to get loginName from email address? Or any other way?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

How about using the following function, Microsoft.SharePoint.Utilities.SPUtility.ResolveWindowsPrincipal()?

It has the following parameters:-

webAppType: Microsoft.SharePoint.Administration.SPWebApplication

inputType: System.String

scopesType: Microsoft.SharePoint.Utilities.SPPrincipalType

inputIsEmailOnlyType: System.Boolean

There are two overloads, suggest you use the SPWebApplication one.

More information at http://msdn.microsoft.com/en-us/library/ee705754.aspx

You can then use the information returned as part of the SPPrincipalInfo object to get the login name to call Ensure User.

share|improve this answer
    
If that doesn't work. Why dont you just write code to retrieve the domain name from Active Directory using the Email address. Should be pretty simple to do. –  Fox Feb 1 '13 at 12:44
add comment

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.