Adding a Publishing Image Field to a SharePoint 2010 Calendar List

As I was working on customizing a SharePoint Calendar, someone asked me if it’s possible to add a Publishing Image Field to a SharePoint Calendar called “Event Image” to display the current event picture. I decided to write this post to explore the options that I have in this case.

 Option #1:

I tried to add a new column to the calendar list, but I couldn’t find a column with the Publishing Image type.


You can add a Hyperlink or Picture Column as shown below, but it has a different behavior in the Add/Edit forms as it doesn’t has a browse dialog to search for image location.

 Option #2:

I tried adding an existing Publishing Image Site Column such as Page Image (found in Page Layout Columns) and it works fine but will keep the name of “Page Image” instead of “Event Image”.

 Option #3:

The 3rd option is to create a custom content type that inherits form the Event Content Type using Visual Studio 2010 and below are the steps to do so:

 To create a SharePoint 2010 content type application solution in Visual Studio 2010

  1. Start Visual Studio 2010.
  2. On the File menu, click New, and then click Project.
  3. In the Installed Templates section, expand either Visual Basic or C#, expand SharePoint, and then click 2010.
  4. In the template pane, click Content Type.
  5. In the Name box, type CustomEvent.
  6. Leave other fields with their default values, and then click OK.
  7. In the What local site do you want to use for debugging? box, select your site.
  8. Select the Deploy as a farm solution box. Then, click Next.
  9. In the Choose Content Type Settings dialog box, in the Which base content type should this content type inherit from? list, select Event.
  10. Click Finish.

To edit the content type details in the Elements.xml file

  1. In Solution Explorer, expand ContentType1 and then open Elements.xml.
  2. Edit the Name attribute in the <ContentType> tag and type CustomEvent.
  3. Edit the Group attribute in the <ContentType> tag to Custom Content Type
  4. Edit the Description attribute in the <ContentType> tag and type Custom Event Content Type.

 To add a field to the Elements.xml file

  1. Above the <ContentType> tag, add the following markup. Notice that this includes a new field that will be identified with a new GUID. For this exercise, you can either use the GUID in the following code or create your own GUID.
  2.   <Field ID=”{66510192-771D-420B-BA43-1AC8AAF69D7E}” Type=”Image” Name=”EventImage” DisplayName=”Event Image” Required=”FALSE” Sealed=”TRUE” RichText=”TRUE”  RichTextMode=”FullHtml”/>
  3. Between the begin and end <FieldRefs> tags in the <ContentType> tag, add the following <FieldRef> tag. Ensure that the GUID matches that of the <Field> in the previous step.
  4.    <FieldRef ID=”{66510192-771D-420B-BA43-1AC8AAF69D7E}” Name=” EventImage” DisplayName=”Event Image” />

To deploy the project

  1. In Solution Explorer, right-click the project, and then click Deploy.
  2. In SharePoint, Go to the Calendar and add the new content type.
  3. Give it a try. 

The Final Markup should look like this:


Additional References:

Leave a Reply