Programmatically upload user profile picture Sharepoint 2010

The first things would be to create a custom screen for uploading a picture into the User Photos Picture library (url – http://SpSite/User%20Photos/Profile%20Pictures).

Then updating the user profile to refer the new uploaded picture. Below is the code that will do just that.

public void UpdateUserPicture(SPSite site)

string userAccount = "domain\\account";

ServerContext ctx = ServerContext.GetContext(site);

UserProfileManager upm = new UserProfileManager(ctx);

UserProfile up = upm.GetUserProfile(userAccount);


up["PictureUrl"].Value = "http://SpSite/User%20Photos/Profile%20Pictures/pic.jpg";