0

This is my situation. I have a farm in which an instance of Sharepoint Foundation is installed.. Windows Server is configure to accept users from 3 trusted domain (xxx, yyy and zzz)

Suppose i have user like:

xxx\u1 yyy\u1

When i told people picker xxx\u1 he cannot resolve the name and ask me to choose between xxx\u1 and yyy\u1...

This is not a problem in that moment, but when I try to access programmatically to users it creates problem..

I access like this:

Web.EnsureUser("xxx\u1");

Is there any other way to do the same thing but with the correct domain\username selection?

Thank you very much!

1 Answer 1

2

I use UserProfile to access this type of data. http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofile.aspx

here's some sample code of using it with people picker

private UserProfile GetExistingEmployee(string CurrentWebSiteURL)
{
    UserProfile profile = null;
    using (SPSite site = new SPSite(CurrentWebSiteURL))
    {
        ServerContext context = ServerContext.GetContext(site);
        UserProfileManager mgr = new UserProfileManager(context);

        using (SPWeb web = site.OpenWeb())
        {
            SPList list = web.Lists["EmployeeData"];
            SPListItem item = list.Items.Add();
            peopleEditor2 = new PeopleEditor();
            peopleEditor2.AutoPostBack = true;
            peopleEditor2.ID = "PeopleEditor2";
            peopleEditor2.AllowEmpty = false;
            peopleEditor2.MultiSelect = false;
            if (existingEmployeePeoplePicker.ResolvedEntities.Count > 0)
            {
                PickerEntity selectedEntity2 = (PickerEntity) existingEmployeePeoplePicker.ResolvedEntities[0];
                profile = mgr.GetUserProfile(selectedEntity2.Key);
                existingEmployeePeoplePicker.AutoPostBack = true;
                return profile;
            }
        }
    }
7
  • Mmm i'm looking for a solution that returns me an SP user.. Do you have any other suggestion? In my solution there are no People Picker or something like that!
    – Ziba Leah
    Mar 7, 2012 at 7:26
  • so, are you wanting to get the logged in user?
    – ironman
    Mar 7, 2012 at 21:33
  • No, I want to get an user which who is in domain but has never come to this sharepoint installation.. When i use ensure user or other commands, it cannot find the user. If I people picker it returns me some suggestion but not immediatly the user.. I'd like to know the commands to make the system do exactly the same calls to AD so that i can solve my problem... If I can, in some way, get an SPUser from AD, I can add it to a "no rights" groups to make the user known to SP..
    – Ziba Leah
    Mar 8, 2012 at 7:33
  • 1
    you can do this - if i'm understanding you correctly. you'll want to do something like this msdn.microsoft.com/en-us/library/ms180885(v=VS.80).aspx . I've got some code that I've written for this sort of thing. If needed let me know.
    – ironman
    Mar 8, 2012 at 15:04
  • The problem is the next step in which i Add the users to SP
    – Ziba Leah
    Mar 8, 2012 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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