This project is read-only.

Automatic create MySite for uses

Mar 18, 2014 at 1:16 PM

I am using your picture upload and it works like a charm. But I have found one problem which is that the users MySite is first created the first time they logon. Is there a way to create it programmatically?
All the users are listed in Office365 but is not available in sharepoint. They are first available in SharePoint after they have logged in the first time. This means that i cannot update their profilepicture before they have logged in the first time.

I have tried to use web.EnsureUser but the only thing this do is to transfer the username to the SiteUserInfoList. The MySite is not created.

Anyone with the same problem? Maybe a solution?
Mar 18, 2014 at 2:25 PM
This is as designed, since we want to minimize the creation of sites, unless they are actually used. If you do have however requirement to pre-create the OneDrive for Business sites beforehand, you can use newly released CSOM and REST interfaces in MSO.

Check more information from the SharePoint Conference session SPC329. Link to video and slides is available from below.
Mar 19, 2014 at 11:28 AM
Edited Mar 19, 2014 at 11:29 AM
Thanks for the reply. I am trying to create a mysite with the rest call(Visual studio c#) they showed in the presentation:
_const string postSiteUri = "_api/sp.userprofiles.profileloader.getprofileloader/CreatePersonalSiteEnqueueBulk";
string postData = "{ 'emailIDs':[‘’]}" ;

But i have some problems with authentication, can you help with the code they used in the presentation or an example? i get the follwoing error:
The remote server returned an error: (403) Forbidden.

Here is the code i use. I get the error when trying to get the response:
          var request = (HttpWebRequest)WebRequest.Create(endPoint);
          ClientContext contextSource = new ClientContext("");
          SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(username, secure);
          contextSource.Credentials = credentials;
          FormDigestInfo diget = contextSource.GetFormDigestDirect();
           request.Headers.Add("X-RequestDigest", diget.DigestValue);
            request.Method = "POST"
            request.ContentLength = 0;
            request.Accept = "application/json;odata=verbose";

            //writing post data to request
            var encoding = new UTF8Encoding();
            var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);
            request.ContentLength = bytes.Length;
            using (var writeStream = request.GetRequestStream())
                  writeStream.Write(bytes, 0, bytes.Length);
            using (var response = (HttpWebResponse)request.GetResponse())
                var responseValue = string.Empty;

                if (response.StatusCode != HttpStatusCode.OK)
                    var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
                    throw new ApplicationException(message);

                // grab the response
                using (var responseStream = response.GetResponseStream())
                    if (responseStream != null)
                        using (var reader = new StreamReader(responseStream))
                            responseValue = reader.ReadToEnd();
Mar 20, 2014 at 8:32 AM
one more thing, if you are talking about the One drive for business site, which means the users personal sites I believe that gets created only once the user logins to the my site host or the -my site collection.
there is a webpart - MySitePersonalSiteUpgradeOnNavigationWebPart a hidden web part on the default page, so when user comes to that page on that instance the my site gets formed.
but when the user is browsing any other site collection in sharepoint the profile of the user gets created but the personal site does not get provisioned? correct me if I am wrong.
Mar 20, 2014 at 1:26 PM
Edited Mar 20, 2014 at 1:33 PM
Code snippet should work if you use the Admin URL and tenant admin account. I'd check those first.
Mar 20, 2014 at 1:33 PM
For vriddhi - We have introduced new APIs for OneDrive for business provisioning. These are explained in following presentation from SPC.

Notice also that you can actually also create the OneDrive for Business site for the particular user using Social CSOM. This API usage is demonstrated in the Contoso.PersonalSiteBranding code scenario in our download. THis part could be executed anywhere in the portal to queue the personal site creation. Anyway if business case is to pre-create the OneDrive for Business sites beforehand for end users, then the new APIs would be the one's to look for.

            // Get user profile
            ProfileLoader loader = ProfileLoader.GetProfileLoader(clientContext);
            UserProfile profile = loader.GetUserProfile();
            Microsoft.SharePoint.Client.Site personalSite = profile.PersonalSite;


            // Let's check if the site already exists
            if (personalSite.ServerObjectIsNull.Value)
                // Let's queue the personal site creation using oob timer job based approach
                // Using async mode, since end user could go away from browser, you could do this using oob web part as well
Mar 20, 2014 at 2:00 PM
I am using both the Admin URL and tenant admin account. So i realy dony know what i am doing wrong.
Mar 20, 2014 at 2:47 PM
I got it to work now :-) Thanks for your help.
Mar 25, 2014 at 3:59 PM
Hi jbitsch,

I am also getting the similar error. Can you tell me what have you done to resolve it?
Mar 25, 2014 at 7:00 PM
Edited Jun 3, 2014 at 2:45 PM

I do not create the onedrive. I create the users MySite and create them as user in sharepoint(from Office 365)
Jun 17, 2014 at 4:20 AM
How can I use that API to get the personal site address for other users though?