Question

I am listening on a particular SPWeb using an SPWebEventReceiver that is successfully firing on the WebMoved event. When the web is moved I update a list with the new location/title.

What I would like to be able to do is listen for when the Web is renamed . Do I do this by attaching an item listener and waiting for an ItemUpdated event? If so I would appreciate a little snippet of code! Thanks!

Was it helpful?

Solution

It looks like this is a bug with the SharePoint OM. The event receiver is clearly supposed to fire when the name of a web is changed, but it does not. It only fires when the Web's URL is changed.

OTHER TIPS

Steve, As far as I can see, SPWebEventReceiver only exposes the following events on an SPWeb (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spwebeventreceiver_members.aspx)

  • SiteDeleted
  • SiteDeleting
  • WebDeleted
  • WedDeleting
  • WebMoved
  • WebMoving

ItemAdded is defined in SPItemEventReceiver which is applicable to SPListItem objects.

The Title property of an SPWeb is stored in a property bag (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.properties.aspx).

It doesn't appear like you can tap into any events when .Update() is called on the property bag, e.g. when Title is updated.

  1. I would say that a rename of the Web name should trigger WebMoved.
  2. Site title rename triggers no action.

Question: What changes do you want tot tap in? Because any metadata for instance could be stored in lists inside, which supports lots of events.

I don't believe it is a bug, I believe it is simply a misinterpretation of the documentation. As you have stated, the documentation indicates that the WebMoving and WebMoved events are triggered by the site's url being modified or being renamed:

from MSDN Doc: "Synchronous Before event that occurs before an existing Web site has been renamed or moved to a different parent object."

However, what gets changed in the UI is NOT the "name" of the site, but the site's title. The SPWeb object does have a "Name" property that is accessible through the Object Model, and updating that Name property and calling SPWeb.Update() does in fact trigger the WebMoved event. The trouble is that this property is not exposed through the web-based settings page for the site, only the "Title" field is exposed, and this field change does not trigger the event. While this seems a bit counter-intuitive and even misleading, if you read the documentation literally, it is behaving exactly as documented.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top