WebHosting

Showing posts with label Create User Profiles programaticaly. Show all posts
Showing posts with label Create User Profiles programaticaly. Show all posts

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();

}

}


}
}

Featured Posts

How to Enable and Configure Remote Desktop (RDP) on Ubuntu 24.04.4 LTS

Remote Desktop Protocol (RDP) support in Ubuntu has become considerably easier with the GNOME Remote Desktop stack included in modern Ubuntu...