SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/'.


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;
                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)
                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"));
share|improve this question
What is your MySites Configuration? – Jesus Shelby Nov 1 '11 at 12:37
Is self-service site creation running on your server? – Alexander Nov 1 '11 at 12:59
yeah..self-service site creation is already running on my server – Jigs Nov 1 '11 at 14:06
@jesus Shelby.. i have pass mysites Host name via function.plz check my below code which is m editing. – Jigs Nov 1 '11 at 14:16
up vote 2 down vote accepted

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


Here is a link to some documentation on the CreatePersonalSite() method.

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

share|improve this answer
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? – Jigs Nov 4 '11 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. – Mike Oryszak Nov 4 '11 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 :( – Jigs Nov 4 '11 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? – Mike Oryszak Nov 4 '11 at 13:43 here i have attach link for Language Pack. – Jigs Nov 4 '11 at 13:59

Your Answer


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.