Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

i am Updating the the status message on user profile to some default value through the code. but now i am getting " Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. "

i am using the below code to do the same

string socialDataStatsSite = "mysiteurl";

        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            SPSite siteColl = new SPSite(socialDataStatsSite);

                SPWeb st = siteColl.OpenWeb();

              //  SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl);
                    HttpContext.Current = null; 
                    ServerContext serviceContext = ServerContext.GetContext(siteColl);
                UserProfileManager manger = new UserProfileManager(serviceContext);

                //  UserProfile userProfile = ProfileLoader.GetProfileLoader().GetUserProfile();
                UserProfile userProfile = manger.GetUserProfile(id);
               // SPContext.Current.Web.AllowUnsafeUpdates = true;
                siteColl.AllowUnsafeUpdates = true;

                userProfile["SPS-StatusNotes"].Value = "default";

                //userProfile[PropertyConstants.StatusNotes].Add(statusMessage);

                userProfile.Commit();


        });
share|improve this question
add comment

1 Answer 1

Your code should look more like this, but the id, is that the username? UserExists(string AccountName) is the reason I am asking. Anyway here is more like what the code should look like. There are a couple of things wrong with your code, so it's hard to tell what exactly is throwing the exception.

        using (SPSite oSite = new SPSite(socialDataStatsSite))
        {
           SPServiceContext oContext = SPServiceContext.GetContext(oSite);
           UserProfileManager oProfileManager = new UserProfileManager(oContext);

           if (oProfileManager.UserExists(id))
           {
               UserProfile oProfile = oProfileManager.GetUserProfile(id);
               oProfile[PropertyConstants.StatusNotes].Value = "default";
               oProfile.Commit();
           }
        }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.