SharePoint 2010 event handler (receiver) not working on personal sites of the MySites site collection

1.6k views Asked by At

I have a SharePoint 2010 MySites set up on its own web application. There is the standard site collection at the base level, http://site:80/.

The personal sites for each user is at the managed URL /personal/.

I have a working event handler which add items to the Newsfeed when a user adds something to a picture library.

THE PROBLEM: The problem is, this only works if they add to a picture library at the base site collection, http://site:80/, and does NOT work if they add to http://site:80/personal/last first/.

Does anyone know why? The event handler feature is site scoped and my understanding is that it should work on all subsites.

2

There are 2 answers

1
Anthony Graglia On BEST ANSWER

Ok. Because you can only 'staple' features to site definitions which will be provisioned in the future, you need a way to activate new features on existing sites.

So, the fix I discovered and used follows:

The default page for the newsfeed is http://site:80/default.aspx. If you create an event receiver and scope it for 'site' and deploy it globally or to that web application, then it will work on the base site collection. Each personal site is a site collection and has the feature but it needs to be activated on each personal site collection.

So, in the default.aspx page, you place the following which will activate the feature if it has not yet been activated.

<script runat="server" type="text/c#">
protected override void OnLoad(EventArgs e) {
  base.OnLoad(e);

  String sAccount = (((SPWeb)((SPSite)SPContext.Current.Site).OpenWeb()).CurrentUser.LoginName).Split('\\')[1];
  String basePersonalURL = "http://site:80/personal/";
  String eventReceiverFeatureId = "12345678-1234-1234-1234-1234567890ab";

  using(SPSite site = new SPSite(basePersonalURL + sAccount)) {
    site.AllowUnsafeUpdates = true;
    using(SPWeb web = site.RootWeb) {
      web.AllowUnsafeUpdates = true;

      try { site.Features.Add(new Guid(eventReceiverFeatureId)); } catch {}

      web.AllowUnsafeUpdates = false;
    }
    site.AllowUnsafeUpdates = false;
  }
}
</script>

You also need to edit the web.config file in order to allow inline code to run for this page. Hope this helps.

3
Nemanja Trifunovic On

The problem is that personal sites are not subsites of My Site host. In fact each user's personal site is a site collection on its own. So basically you need to register your event receiver not only for My SIte host, but also for each user's personal site.