0

I am using sp 2013. When I click on "Sites" in the top bar I go to this page:

http://mijn.companyName.com/persoonlijk/hajjk1/Social/Sites.aspx#IsEditing_WPQ4=1

Is it possible to provision a custom webpart on this page for each new mysite? enter image description here

1

Yes, it is possible. The best approach would be a feature with a feature receiver that you would activate (programmatically or via PowerShell script every time you create a MySite).

Take a look at the following pseudo code which should be in the future receiver:

var web = SPContext.Current.Web;
var mySitePage = web.GetPage(web, SPUtility.ConcatUrls(web.Url, _NEWPAGE_PATH_));
if (mySitePage != null && mySitePage .Exists)
{
   using (SPLimitedWebPartManager webPartManager = mySitePage.GetLimitedWebPartManager(PersonalizationScope.Shared))
   {
      var yourCustomWebPart = new YourCustomWebPart();
      webPartManager.AddWebPart(yourCustomWebPart, "_WEBPARTZONE_LOCATION_", 1);
      webPartManager.SaveChanges(yourCustomWebPart);
   }
}

_NEWPAGE_PATH_ should be your current MySite page file name.

_WEBPARTZONE_LOCATION_ should be your web part zone location.

If you need any clarification, please let me know.

  • hi, this looks good, but we are using the OOTB logic to create a new mysite? When someone clicks on the hyperlink "Sites" in the top bar, SharePoint will automatically creates a site collection as a mysite. – Ola Apr 13 '15 at 14:35
  • Controlling the creation of site collections is not an easy task (not like it's with web sites, where you can handle the web added event). Have you considered pre-provisioning MySites after an AD user has been created and synchronized with SharePoint? Take a look at the following, this works for 2013 as well: gallery.technet.microsoft.com/office/… In that case you would just activate a feature with a feature receiver code. – Paul Strupeikis Apr 13 '15 at 14:40
  • what about a daily scheduled timerjob which loops in all mysites and add the webpart to the startpage (if the webpart is not already exist)? We do not want pre create mysites for all users. – Ola Apr 14 '15 at 11:00
  • Sure. That would work. Easy, fast and effective solution. – Paul Strupeikis Apr 14 '15 at 12:59
  • what about a delegate control which starts when you go to your mysite? Or feature stapling? – Ola Apr 16 '15 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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