0

Basically I am making a timer job to send a birthdayWish email fetched from SharePoint userprofile service. But problem is I have multiple userprofile services on server.

like 1). userprofile service1
2). userprofile service2
3). userprofile service3
4). userprofile service4

So how to use 2nd user-profile service.

Here's some code, that I did:

    SPServiceContext oServiceContext = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);

     UserProfileManager oProfileManager = new UserProfileManager(oServiceContext);

So here in SPServiceApplicationProxyGroup.Default its getting 1st user-profile.

Among them I want to use 2nd user-profile service. but by default when trying to access its getting 1st user-profile service and iterate through it.

So how to set it to use 2nd user-profile service.

1 Answer 1

0

My guess is that you have one User Profile Service Instance (UPS) with multiple User Profile Service Applications (UPA) on it (and not multiple UPS):

var userAppName = "userprofile service2";
SPFarm farm = SPFarm.Local;

SPServiceApplication application;
foreach (SPService s in farm.Services)
{
    if(s.TypeName.Contains("User Profile Service"))
    {
        //We found UPS
        foreach(SPServiceApplication app in s.Applications)
        {
            if(app.Name == userAppName)
                application = app; //Here is UPA
        }
    }
}

//Or if you like oneliner (not 100% safe)
var x = farm.Services.First(s => s.TypeName.Contains("User Profile Service"))
          .Applications.FirstOrDefault(app => app.Name == userAppName);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I will check & get back to you.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.