Hi i am using below code for update sharepoint userprofile
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
HttpContext con = HttpContext.Current;
SPSite tempSite = new SPSite(SPContext.Current.Site.Url);
SPUserToken superToken = tempSite.SystemAccount.UserToken;
string sAccount = string.Empty;
UserProfile profile = null;
using (SPSite site = new SPSite(SPContext.Current.Site.Url, superToken))
{
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPServiceContext context = SPServiceContext.GetContext(site);
HttpContext.Current = null;
UserProfileManager profileManager = new UserProfileManager(context);
SPUser NewUser = web.EnsureUser(spuser);
sAccount = NewUser.LoginName;
if (!profileManager.UserExists(sAccount))
{
profile = profileManager.CreateUserProfile(sAccount);
}
else
{
profile = profileManager.GetUserProfile(sAccount);
}
web.AllowUnsafeUpdates = false;
}
// profile["AccountName"].Value = createusert1.UserName;
profile["FirstName"].Value = "Test";
profile.Commit();
});
}
catch (Exception ex) {}
this code works perfect and save data in userprofile but after complete this code execution error come in browser object reference not set to an instance of an object
why this done. any idea it's comes for any user update his own profile also. no error in code but error in browser. why? any Idea?