SharePoint 2010 – Updating custom forms on an existing list

What do you do when you have a list with custom forms (editform.aspx, dispform.aspx and newform.aspx) and you want to add some extra fields on that form.

Ok, so you get SharePoint Designer out and make the modifications to the forms. But how do we deploy this?

First I created a feature with an FeatureActivated Method

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

   SPWeb web = (SPWeb)properties.Feature.Parent;

   SPList list = web.Lists[“Project Status Report”];

   //Get the Content Type used for this list

   SPContentType ctCustom = list.ContentTypes[“MyContentType”];

   if (ctCustom == null)

  {

       throw new NullReferenceException(“Content Type MyContentType not found”);

   }

   else

  {

         // Update Edit, Display and New Forms

ctCustom.EditFormUrl = “Lists/MyList/csEditForm.aspx”;

ctCustom.NewFormUrl =“Lists/MyList/csNewForm.aspx”;

ctCustom.DisplayFormUrl =“Lists/MyList/csDispForm.aspx”;

ctCustom.Update(false); //do not update children
}

}

Now all we have to do is add the forms to the library (adding the forms to other locations will give you errors related to the master page file).

In the same feature add the forms to a Forms Folder and update the elements.xml of the feature with the following content. Make sure that you give the forms a name different from the standard editform.aspx, newform.aspx and dispform.aspx. As this will not replace existing forms.

<?xmlversion=1.0encoding=utf-8 ?>

<Elements xmlns=http://schemas.microsoft.com/sharepoint/>

<Module Name=ListForms Url=Lists/MyListPath=Forms>

   <File Url=csEditForm.aspxName=csEditForm.aspxType=GhostableIgnoreIfAlreadyExists=TRUE />

   <File Url=csDispForm.aspxName=csDispForm.aspxType=GhostableIgnoreIfAlreadyExists=TRUE />

   <File Url=csNewForm.aspxName=csNewForm.aspxType=GhostableIgnoreIfAlreadyExists=TRUE />

</Module>

</Elements>


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Avatar of Pieter Veenstra

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@sharepains.com

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains

Subscribe now to keep reading and get access to the full archive.

Continue reading