Modify list forms.


Hello everyone,

Today I’ll talk about the steps required to change pages lists forms (new,edit,display).

Those pages are in fact webpart pages, so we can add elements to customize our forms. (Text, Image, Button, etc …)

Looking for information, I realized that I found mostly tutorials to make changes via SharePoint Designer and very little via code server.

Personally for the sake of reusability, I prefer use wsp packages containing my changes instead of working with SPD.

Here are the steps necessary to change the “form” of a list.

Go to your Visual Studio Solution.

1) Within your list definition, add a new “Application Page”.

Just use the standard “Application Page” Template available when you select “Add new item”.

01

2) Change deployment type of this page.

In the page properties, select « Element File ».

02
3) Copy the contents of the default SharePoint form.

Creating our aspx page using Visual Studio, we have a file looking like this.

03
To continue, we only need the specific elements of our solution namely the import of the solution assembly and the link to the page with cs source code.

So delete the rest for a file containing only our two lines.

04

If we look at the contents of the file “Schema.xml” our list definition, we can see that the forms rely on the “form.aspx”

05

This page is located in the 14 Hive, within the folder « TEMPLATE\Pages »

06

Open this page and then copy the entire page in our “Application Page”. Done, delete the tag “Page” copied from the file “form” of SharePoint

07

Also change the parameter « DynamicMasterPageFile=”~masterurl/default.master”

» by « MasterPageFile=”~masterurl/default.master” » within the tag « Page »

4) Page code behind.

The code behind must inherit from the class Microsoft.SharePoint.WebPartPages. WebPartPage

08

5) Associate the new page as a new “Form” from the list.

In our file “schema.xml” we will modify the forms associations, we will change the parameter “SetupPath” by  “Path” which will target our new page.

09

Become

10

With these changes we have replaced the “new form” of our page.

To test our changes, we will add a message on the page.

In our file “ApplicationPage1.aspx” seek the happy place holder “PlaceHolderMain” and add our text.

11

Now deploying our solution and let’s add an element.

12

This approach allows using the native component added, however we may also use another component or even a standard component by changing the parameters.

To do this, simply specify in schema.xml that we do not use the standard ListForm and inform the Web Part that you want to use.

In the example below, we will change the edit form, we will use the standard Web Part and add a content editor webpart.

14

After deploying the edit form contains the content editor webpart.

15

One last example, if we do not use the default list form webpart , we can use the parameter “UseDefaultListFormWebPart =” False “”

16

Et voilà !

Christopher.

Advertisements

2 thoughts on “Modify list forms.

  1. Ryan

    Good write-up!
    I followed what you did to the T and stopped at just displaying Hello World.
    Only thing is, it loads NewForm.aspx, and before rending is completed, it redirects to an OOTB form in the layouts directory. I can’t find any references to this OOTB form so I can not figure out what it is doing this.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s