Click here to Skip to main content
15,867,308 members
Articles / Productivity Apps and Services / Microsoft Office
Article

Accessing SharePoint UserProfile Services in Infopath 2007

Rate me:
Please Sign up or sign in to vote.
3.33/5 (2 votes)
26 Apr 2007 32K   14  
Access UserProfile Services in Infopath 2007.

Screenshot - Infopath_Security_Trust.jpg

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.

C#
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.

    Screenshot - UserProfileService_Asmx.jpg

  • Now select 'Accept Client Certificate' and say OK.

    Screenshot - SecureCommunications.jpg

This will enable the Infopath form to access UserProfile service from a different machine.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --