Export (0) Print
Expand All

UserProfileService class

Provides a Web service to manage user profiles.

Namespace:  WebSvcUserProfileService
Assembly:  UserProfileServices (in UserProfileServices.dll)

[XmlIncludeAttribute(typeof(PropertyData[]))]
[WebServiceBindingAttribute(Name = "UserProfileServiceSoap", Namespace = "http://microsoft.com/webservices/SharePointPortalServer/UserProfileService")]
[XmlIncludeAttribute(typeof(ValueData[]))]
[XmlIncludeAttribute(typeof(SPTimeZone))]
public class UserProfileService : SoapHttpClientProtocol

The following example shows how to get information about the membership of a user, colleagues of a user, links, and user profile property data. Make sure you add a Web reference to a UserProfileService Web service site to which you have access. Change the using GetProfileDataSample.MyServer002; directive to point to the Web service site you are referencing. In addition, replace "domain\\username" with valid values.

using System;
using System.Collections.Generic;
using System.Text;

// TODO 
// Change the using GetProfileDataSample.MyServer002 directive
// to point to the Web service you are referencing.
using GetProfileDataSample.MyServer002;

namespace GetProfileDataSample
{
    class Program
    { 
        //Instantiate the Web service. 
        public static UserProfileService userProfileService = new UserProfileService();

        static void Main(string[] args)
        {
            //Set credentials for requests.
            //Use the current user log-on credentials.
            userProfileService.Credentials =
                System.Net.CredentialCache.DefaultCredentials;

            GetUserProfilePropertyData();
            GetUserMemberships();
            GetUserColleagues();
            GetUserLinks();
        }

            static void GetUserProfilePropertyData()
        {
            // TODO 
            // Replace "domain\\username" with valid values.
            PropertyData[] properties = 
                userProfileService.GetUserProfileByName("domain\\username");
            for (int i = 0; i < properties.Length; i++)
            {
                Console.WriteLine(properties[i].Name);
                Console.WriteLine(properties[i].Values);
            }

            Console.Read();
        }
         static void GetUserMemberships()

        {
            // TODO 
            // Replace "domain\\username" with valid values.
            MembershipData[] memberships = 
                userProfileService.GetUserMemberships("domain\\username");
            for (int i = 0; i < memberships.Length; i++)
            {
                Console.WriteLine(memberships[i].DisplayName);
            }

            Console.Read();
        }

        static void GetUserColleagues()
        {
            // TODO 
            // Replace "domain\\username" with valid values.
            ContactData[] contacts = 
                userProfileService.GetUserColleagues("domain\\username");
            for (int i = 0; i < contacts.Length; i++)
            {
                Console.WriteLine(contacts[i].Name);
            }
            Console.Read();
        }

        static void GetUserLinks()
        {
            // TODO 
            // Replace "domain\\username" with valid values.
            QuickLinkData[] links = 
                userProfileService.GetUserLinks("domain\\username ");
            for (int i = 0; i < links.Length; i++)
            {
                Console.WriteLine(links[i].Url);
            }

            Console.Read();
        }
        }
    }

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft