About Me

My photo
a Dynamic and Energetic guy.....

Friday, October 17, 2008

MySite Creation Programatically

ServerContext context = ServerContext.GetContext(site);

UserProfileManager profileManager = new UserProfileManager(context);

foreach(UserProfile userProfile in
profileManager)

{try
{
string userName =userProfile[PropertyConstants.AccountName].Value.ToString();

Logger.LogDebug("Creating
personal site for user : "
+ userName);

userProfile.CreatePersonalSite();
Logger
.LogDebug("Created
personal site for user : "
+ userName);

SPSite personalSite = userProfile.PersonalSite;

using(SPWeb web = personalSite.OpenWeb())
{

if
(!Utility.ListExists(ConfigurationInfo.PhotoLibraryDisplayName,web))
{
SPListTemplateType templateType = SPListTemplateType.PictureLibrary;
Guid
listId = web.Lists.Add(ConfigurationInfo.PhotoLibraryDisplayName,null, templateType);

SPList PhotoLibrary = web.Lists[listId];
PhotoLibrary.Description = "This is a picture library to show photos";

PhotoLibrary.Title= ConfigurationInfo.PhotoLibraryDisplayName;
PhotoLibrary.OnQuickLaunch= true;
PhotoLibrary.Update();

web.AllowUnsafeUpdates = true;
web.Dispose();

}

}

}


catch(Exception ex)

{
Logger
.LogDebug("error while creating MySite :" + ex.Message);
}
}

No comments:

My Masters