Monday, August 8, 2011

Create User Profiles using SharePoint Object Model

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
using System.Web;
using Microsoft.SharePoint.WebControls;
using System.Web.Profile;
using Microsoft.SharePoint.Portal.WebControls;

namespace add_user.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{

public string AccountName { get; set; }

public string WorkPhone { get; set; }


public string Department { get; set; }

public string Title { get; set; }

public string DistinguishedName { get; set; }

public string WorkEmail { get; set; }

public string Office { get; set; }

protected void Button1_Click(object sender, EventArgs e)
{

Create();
}

public void Create()
{

string socialDataStatsSite = SPContext.Current.Site.Url;

using (SPSite siteColl = new SPSite(socialDataStatsSite))
{
AccountName = "alok";
WorkPhone="9886178862";
Title="Mr";
DistinguishedName="alok";
WorkEmail="alok@pointcross.com";
Office = "Pointcorss";
SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl);

UserProfileManager userProfileManager = new UserProfileManager(serviceContext);

UserProfile newProfile = userProfileManager.CreateUserProfile(AccountName, AccountName);

newProfile[PropertyConstants.WorkPhone].Add(WorkPhone);

newProfile[PropertyConstants.Department].Add(Department);

newProfile[PropertyConstants.Title].Add(Title);

newProfile[PropertyConstants.DistinguishedName].Add(AccountName);

newProfile[PropertyConstants.Office].Add(Office);

newProfile.Commit();

}

}


}
}

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...