Recently, I got a requirement to define custom pages for a content type item. What am I talking about? If that’s the question these are the pages which open when you try to open, edit and create an item from the list.

So the best way to customize these pages is to add these pages entry to the custom content type. You can create your page (Either same for all the three or separate pages) and add them to the layouts folder.

You can then reference these pages in the content type’s element.xml file. So your content type elements.xml file would look like:

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:   <ContentType ID="0x010800b1684200801b11ddbcb20050c2490048"
   4:                Name="Publication Approval Content Type5"
   5:                Group="Publication Approval Workflow"
   6:                Description="5 Custom Workflow Task for the Publication Approval Workflow"
   7:                Version="0"
   8:                Hidden="FALSE">
   9:     <FieldRefs>
  10:       <FieldRef ID="{81561b40-7aae-11dd-9b5a-0050c2490048}"
  11:                 Name="_NotifyIR"/>
  12:     </FieldRefs>
  13:     <XmlDocuments>
  14:       <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
  15:         <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
  16:           <Display>_layouts/PublicationApprovalForms/TaskEditForm/TaskEditForm.aspx</Display>
  17:           <Edit>_layouts/PublicationApprovalForms/TaskEditForm/TaskEditForm.aspx</Edit>
  18:           <New>_layouts/PublicationApprovalForms/TaskEditForm/TaskEditForm.aspx</New>
  19:         </FormUrls>
  20:       </XmlDocument>
  21:     </XmlDocuments>
  22:   </ContentType>
  23: </Elements>

Add this code to the elements.xml of the content type and then re-install and activate the content type. And Voila your pages would be customized.

One more thing, if you would like to do the above programmatically then it is easier then the above way. (Of course you would have to create the aspx pages.)

   1: using (SPSite site = new SPSite("http://Site/"))
   2: {
   3:     using (SPWeb web = site.OpenWeb())
   4:     {
   5:         SPList list = web.Lists[documentlibrary];
   6:         SPContentType ct = list.ContentTypes[contentType];
   7:         if (!on)
   8:         {
   9:             ct.EditFormUrl = string.Empty;
  10:             ct.NewFormUrl = string.Empty;
  11:             ct.DisplayFormUrl = string.Empty;
  12:          }
  13:          else
  14:          {
  15:              ct.EditFormUrl = "_layouts/whateverEdit.aspx";
  16:              ct.NewFormUrl = "_layouts/whateverNew.aspx";
  17:              ct.DisplayFormUrl = "_layouts/whateverDisplay.aspx";
  18:          }
  19:          ct.XmlDocuments.Delete("http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url");
  20:          ct.Update();
  21:          list.Update();
  22:      }
  23:  
  24: }