Introduction
This article explains how to access SharePoint Userprofile Services in Infopath Form. It also explains about the configuration settings.
Using the code
This code assumes that the SharePoint(MOSS) server contains EmployeeId and Preferred Name properties.
First add a web reference (http://MOSSSERVERNAME/_vti_bin/userprofileservice.asmx). I gave the web reference name as localhost. If you like, you can have a different name. Then you have to change the code.
private string GetUserProfileByEmployeeId(string EmpId)
{
string displayName = string.Empty;
localhost.UserProfileService myUPWS = new localhost.UserProfileService();
myUPWS.Credentials = System.Net.CredentialCache.DefaultCredentials;
long profileCount = myUPWS.GetUserProfileCount();
localhost.GetUserProfileByIndexResult up;
localhost.PropertyData[] propdata;
for (int j = 0; j < profileCount; j++)
{
up = myUPWS.GetUserProfileByIndex(j);
propdata = up.UserProfile;
if (propdata[propdata.Length - 1].Values.Length > 0)
{
if (propdata[propdata.Length - 1].Values[0].Value.ToString()
== EmpId)
{
displayName = propdata[4].Values[0].Value.ToString();
break;
}
}
}
return displayName;
}
So, the above code returns the Preferred Name when you pass EmployeeId
to the UserProfile Services. Since we are using webservices in the Infopath form, we have to change the Security Level to "Full Trust". Also, if the form is to be accessed from a different machine other than the development machine or the MOSS server machine, we have to sign the form.
In addition, we have to configure the IIS of the MOSS server so that Infopath form can access UserProfile Services from a different machine.
- Go to IIS and look for UserProfileServices.asmx file and click on Properties.
- Click on 'Edit' on Secure Communications section.
- Now select 'Accept Client Certificate' and say OK.
This will enable the Infopath form to access UserProfile service from a different machine.