Recover NewForm.aspx from the dead in Sharepoint 2007

Have you nuked your NewForm.aspx  page in Sharepoint WSS/MOSS 2007?   This can happen if you remove the default list web part from the page and save the file.  The problem is apparently that any time you create a custom list form web part, it grabs the latest fields from NewForm.aspx not from the list settings.  Go figure.

So without warning you can totally destroy your NewForm page and also cause problems for every custom form you might spawn off of it.  To save yourself from this disaster (which should not be possible in the first place IMO) follow the instructions below (these instructions were originally posted by David Szabo here):

  1. Open NewForm.aspx and EditForm.aspx in Sharepoint Designer
  2. Copy the code for the ListFormWebPart control from the EditForm.aspx. The code in question reaches from
    <WebPartPages:ListFormWebPart runat=”server” __MarkupType=”xmlmarkup” WebPart=”true” __WebPartId=”{YOUR_GUID}” >down to 

    </WebPartPages:ListFormWebPart>

  3. Paste it into the broken NewForm.aspx, I pasted it right below the Line:<WebPartPages:WebPartZone runat=”server” FrameType=”None” ID=”Main” Title=”loc:Main”><ZoneTemplate>
  4. Within the pasted lines of code look up the lines starting with<ControlModeand

    <FormType

    In the “Control mode” tag replace the “Edit” with “New”, in the “FormType”-Section replace the digit “6” with “8”.

  5. Before saving, you have to generate a new GUID for the pasted control in your NewForm.aspx otherwise your EditForm.aspx will be broken after saving!!!There are online GUID generators on the internet so you don’t need Visual Studio, e. g.:http://www.somacon.com/p113.php

    Generate a new GUID and asign it to the “__WebPartId” attribute in the very first line of code of your control:

    <WebPartPages:ListFormWebPart runat=”server” __MarkupType=”xmlmarkup” WebPart=”true” __WebPartId=”{YOUR_NEW_GUID_HERE}” >

  6. Look up the <ID></ID>-Tag further below (it was about 27 lines below in my case) and change a random number in the ID, e. g.Before: <ID>g_092cc5f1_f97c_408b_bf66_c7b235af38f9</ID>After:

    <ID>g_092cc5f1_f97c_408b_bf66_c7b235af38f5</ID>

  7. Save your work…and your done!

Thank you to David for posting the solution.  This definitely helped with some issues we had this week.  I really should have known better but I was operating under the assumption that I did not at any point need to use the standard NewForm.aspx page any longer.  What I didn’t realize was that once you overwrite the file it becomes the new site definition.  This means you cannot simply right-click and “reset to site definition” as you might expect.  You might be familiar with this if you have customized your default.aspx page and would like to restore it.

I also didn’t realize that when you make changes to your list they will not show when you re-add the Custom List Form control (see below).

To ensure this doesn’t happen when you create custom forms in Sharepoint 2007  do the following:

  1. Create a copy of NewForm.aspx (or right-click and select New From Existing Page)
  2. Remove or hide the default list web part
  3. From the menu select Insert->Sharepoint Controls->Custom List Form
  4. Select the appropriate list (the defaults should be for a new form)
  5. Hit Okay

Now you just need to make sure that any links pointing to NewForm go to your new page.  But in this way you don’t have to worry about screwing up your NewForm page and any subsequent custom forms you may derive from it.

Alternatively you can indeed customize NewForm and make it work, just make sure you hide the default part rather than deleting it.

9 comments

Leave a comment