Thursday 26 January 2012

Using GUID instead of class name

I will demonstrate on example of adding Event Receiver.

Create Event Receiver, open class file.
First add this:
using System.Runtime.InteropServices;

Then add this above class (use GUID Generator):
[Guid("567de298-a813-42ad-a639-26af24ad77b0")]
public class GoleszympansyEventReceiver : SPItemEventReceiver

Now, let's imagine you want to change class name or namespace. You'll have to change it also in Elements.xml.
But not anymore. Just insert this into elements.xml:
<Class>$SharePoint.Type.567de298-a813-42ad-a639-26af24ad77b0.FullName$</Class>

Guid here MUST be lower case. Just paste Guid from GUID Generator and then select it and press Ctrl+U.

Now the compiler will take care of the rest.

Full list of replaceable parameters can be found here: http://msdn.microsoft.com/en-us/library/ee231545.aspx

No comments:

Post a Comment