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”.
2) Change deployment type of this page.
In the page properties, select « Element File ».
3) Copy the contents of the default SharePoint form.
Creating our aspx page using Visual Studio, we have a file looking like this.
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.
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”
This page is located in the 14 Hive, within the folder « TEMPLATE\Pages »
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
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
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.
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.
Now deploying our solution and let’s add an element.
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.
After deploying the edit form contains the content editor webpart.
One last example, if we do not use the default list form webpart , we can use the parameter “UseDefaultListFormWebPart =” False “”
Et voilà !