Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

70-488 Create Content Type Event Receiver

Posted by Paul on December 16, 2014


In this article we can explore how to create a content type event receiver.

Scenario

We are using an existing content type of template type Contact. We are adding an event receiver which operates on the Item Add event. For time being, we are just using the event receiver to block the item adding with an error message.

Steps

Open Visual Studio and create a SharePoint 2013 Farm Solution.

image

Add a new Event Receiver as shown below.

image

Open the XML file and choose the template id as 105.

image

In the event handler code, use the following statements.

image

Now you are ready with the event receiver. Build & Deploy the project.

image

Testing the Event Receiver

Create a new Contacts list in SharePoint.

image

Try adding a new item & Save it. You should get the following error.

image

This concludes our simple example of using event receiver against content types. The above event receiver will fire for all the Contact content type instances.

You may wish to use advanced property manipulation based on your business scenario.

image

You can use SharePoint Manager a free tool for examining events for a content type. The tool is downloadable from: http://spm.codeplex.com/

References

http://msdn.microsoft.com/en-us/library/ee231563.aspx

Summary

In this article we have explored how to create an event receiver for a content type.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s