4

I am trying to create MySites for users programmatically but I am receiving the following error:

My Site creation failure for user '' for site URL 'http://goaccel-app2:1000/sites/mysites/personal/'.

Exception:

Microsoft.Office.Server.UserProfiles.PersonalSiteCreateException: A failure was encountered while attempting to create the site. ---> Microsoft.SharePoint.SPException: User cannot be found.

I am using Forms Based Authentication (FBA) with SharePont 2010 Foundation

This is the code I am using:

public void MySite(SPUser AdminUser,string username, string sitehost)
    {
       sitehost agrument given <mysitehost domain>
        var superToken = AdminUser.UserToken;
        UserProfile profile = null;
        HttpContext con = HttpContext.Current;
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                string sAccount = string.Empty;
                using (SPSite site = new SPSite(sitehost, 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(web.CurrentUser.LoginName);
                    SPUser NewUser = web.EnsureUser(username);
                  SPUser NewUser = web.EnsureUser(web.CurrentUser.LoginName);
               sAccount = NewUser.LoginName;
   if (profileManager.UserExists(sAccount))
       {
     profile = profileManager.GetUserProfile(sAccount);
           if (profile.PersonalSite == null)
               {
                profile.CreatePersonalSite();
                SPSite newSite = new SPSite(profile.PersonalSite.ID);
              SPWeb newWeb = newSite.RootWeb;
                 newWeb.SiteAdministrators.Add(NewUser.LoginName, NewUser.Email, NewUser.Name, NewUser.Notes);
             newWeb.Features.Add(new Guid("9DCBD980-1FE9-421B-90FD-4FE766D02A65"));
  }
}
4
  • What is your MySites Configuration? Nov 1, 2011 at 12:37
  • Is self-service site creation running on your server?
    – Alexander
    Nov 1, 2011 at 12:59
  • yeah..self-service site creation is already running on my server Nov 1, 2011 at 14:06
  • @jesus Shelby.. i have pass mysites Host name via function.plz check my below code which is m editing. Nov 1, 2011 at 14:16

1 Answer 1

2

To create a personal site for a user you should be using something like this:

profile.CreatePersonalSite();

Here is a link to some documentation on the CreatePersonalSite() method. http://msdn.microsoft.com/en-us/library/ms518678.aspx

Also, be sure to properly dispose your SPSite and SPWeb objects.

5
  • My doubts is when m going in Central Administration-Manage service application-User Profile Service- Mysite Setting -> Setup My sites. when m click on Setup Mysites link i got this one error "Cannot create an object of type 'Microsoft.SharePoint.Portal.WebControls.LocStringId' from its string representation 'SiteAdminPersonalSite_SocialSecurityTrimmerEnabledSectionTitle_Text' for the 'TitleLocId' property. " so my thoughts thats this issue causes problem when in Create mysite. Do you have any idea to solve this issue? Nov 4, 2011 at 6:22
  • Was this a new install or an upgrade from a previous version? What language packs do you have installed? The error you mentioned suggests other technical issues with the farm. Nov 4, 2011 at 12:33
  • without upgrading i facing this error than after I upgraded sharepoint Server 2010 with August 2010 CU(After Searching Google).. Till I got this error :( Nov 4, 2011 at 13:30
  • You didn't answer the language pack question. The items you listed are related to localization. Which language packs are installed, and were those properly patched? Nov 4, 2011 at 13:43
  • screencast.com/t/2bUMX2YBTN here i have attach link for Language Pack. Nov 4, 2011 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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