Raghu's SharePoint Corner: SSP

My blog has moved!

You will be automatically redirected to the new address. If that does not occur, visit
http://www.sharepointcolumn.com
and update your bookmarks.

Showing posts with label SSP. Show all posts
Showing posts with label SSP. Show all posts

November 13, 2008

How to retrieve User Profile Properties of User From SSP

This article will be concentrating on how to retrieve user profile properties from SSP.In order to retreive user profile properties from SSP you need to first import all the Active Directory users to SSP.

Once the users are imported you can start accessing the user profiles. The following are the assmblies that will be used in order to achieve this

1. Microsoft.Office.Server
2. Micorsoft.Office.Server.UserProfiles
3. Microsoft.Office.Administration
4. And finally Microsoft.SharePoint

using (SPSite site = new SPSite(SSPsiteURL))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        UserProfileManager manager = new UserProfileManager(ServerContext.GetContext(web.site));
UserProfile profile = manager.GetUserProfile(web.CurrentUser.LoginName);
                        string deptName = profile["Department"].Value.ToString();
                    }
                }

Department is a user profile property in ssp. Similarly you can access all the properties of a user from ssp

In order to iterate through all the user profiles in ssp, please go through my below post

Happy coding !

October 8, 2008

Iterating UserProfiles in Shared Service Provider (SSP)

Iterating UserProfiles in Shared Service Provider (SSP)

This article deals with retrieving user profiles of all the user that exists in shared service provider. There may be many scenarios where you need to iterate through all the userprofiles that exist in ssp. There is no such method available out of the box in MOSS where you can get list of user in Shared Service Provider. In order to iterate each profile in shared service provider we need to use Ienumerators

I had a scenario where I need to activate features on all the mysites that exist. In order to activate feature on individuals mysite, I first need to check whether the user has a mysite and then activate the feature.

When you are trying to do this you may come across some Permission and Access Denied exception. Here is the links which will help you to solve the issue

http://edinkapic.blogspot.com/2007/08/enumerating-user-profiles.html

You can retrieve users from SSP by using web services. The below code iterates a list of user from SSP

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Collections;
using System.IO;

using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
public namespace SSPUsers
{
public class Program
{
static void Main(string[] args)
{
using (SPSite searchSite = new SPSite("http://sspsiteurl"))
{
UserProfile currentProfile;
bool checkPersonalSite;

// Use the ServerContext to get the SSP associated to the site collection of interest

ServerContext context = ServerContext.GetContext(searchSite);

// Get the user profile enumerator for the targeted SSP

UserProfileManager profileManager = new UserProfileManager(context);

long count = profileManager.Count;

IEnumerator enumerator = profileManager.GetEnumerator();

bool continueEnum = true;

while (continueEnum)

{

try

{

continueEnum = enumerator.MoveNext();

}

catch (Exception e)

{

Console.WriteLine("EXCEPTION in enum - try to move to next: " + e.ToString());

continueEnum = enumerator.MoveNext();

}

currentProfile = (UserProfile)enumerator.Current;

}

}

}

The currentProfile object will give you access to all the properties of a user availabel in the ssp