Showing posts with label Sharepoint web service. Show all posts
Showing posts with label Sharepoint web service. Show all posts

Wednesday, May 11, 2011

Retrieving Picture URL or User Info from sharepoint webservices


First add the web reference to the userprofileservice.asmx

http://serverURL/_vti_bin/userprofileservice.asmx



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Net;
using ConsoleApplicationSharepointTesting.WebServiceMyReference;  (Name of the Web reference)    

namespace ConsoleApplicationSharepointTesting
{
class Program
{
static void Main(string[] args)
{
PropertyData[] userDetails;
UserProfileService userprof = new UserProfileService();
SPSecurity.RunWithElevatedPrivileges(delegate()
{

userprof.PreAuthenticate = true;
userprof.Credentials = new NetworkCredential("UserName", "Password", "Doamin");
userDetails = userprof.GetUserProfileByName("Domain\UserName");

if (userDetails != null)
{

Console.WriteLine(userDetails[15].Name + " Path of the Image -------" + userDetails[15].Values[0].Value.ToString());

}

Console.Read();
});


Where index 15 refers to the PictureURL

2 refers to the FirstName
4 refers to the LastName

For NetworkCredential(....) use System.Net Namespace

By using foreach loop we can get all the details of the user.
kindly do check in the loop

userDetails[Index].Values have a value, otherwise we will be getting the index out of range runtime error.




Sharepoint smoking ........
Dharani