Sharepoint 2010 Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint 2010       RSS Feeds

SharePoint 2010 - deploying custom forms

  Asked By: Callie    Date: Sep 08    Category: Sharepoint 2010    Views: 4285

I have custoimized a newform.aspx in sharepoint designer using a

How can I deploy it as a feature along with a list defintion ?

if I specify

<Form Type="NewForm" Url="MyNewForm.aspx" WebPartZoneID="Main"/>

in my list defintion, SharePoint never provision datafarmwebpart, it always
replace it by default listform.



2 Answers Found

Answer #1    Answered By: Thomas Davis     Answered On: Sep 08

It took me a while to get this right. I hope it works for you...

The default list forms automatically add a ListFormWebPart control to the
pages/forms.aspx page in the "14" hive to arrive at the list's new, edit, and
display forms. You can add additional web parts to the form as well. Luckily,
there is a property that tells SharePoint not to add a ListFormWebPart by
default, so the only web parts on the list's forms are the ones you specify.
(Sorry if my explanation is not yet clear.)

First, you need to export your custom web part. You can go to the page
(newform), view the page in edit mode, and export the dataformwebpart (click the
little smart tag down arrow and export). This will result in a .webpart file
that has necessary xml in it for a future step...

Next, in your Form tag in the list definition, add the following attribute:

Next, add the web part's xml in the appropriate place like so:

<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx"
WebPartZoneID="Main" UseDefaultListFormWebPart="FALSE">
<AllUsersWebPart WebPartOrder="2" WebPartZoneID="Main"



Finally, you have to remove references to the List's ID in the web part's
exported xml. When you deploy as a feature, you will not know the ID of the
list, so you want to be as generic as possible. I removed properties like
ListId, ListName (which is just the ID again), etc., and replaced it with
ListUrl because I was deploying a list instance, not a List Definition. I was
unable to find a ListId token that would be replaced automatically, so this may
be a challenge for you.

Note the ListUrl property and how I replaced the "ListID" ParameterBinding with
a CAMLVariable instead of the explicit guid.

<property name="ListUrl" type="string">Lists/Risks</property>
<property name="ParameterBindings" type="string">
<ParameterBinding Name="ListItemId" Location="QueryString(ID)"
<ParameterBinding Name="ListID" Location="CAMLVariable"
<ParameterBinding Name="MaximumRows" Location="None"
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="ManualRefresh"
<ParameterBinding Name="UserID" Location="CAMLVariable"
<ParameterBinding Name="Today" Location="CAMLVariable"

I hope my hours (ah hem... or days) of fighting with this helps!

Please let me know if there is anything else I can do to help.

Answer #2    Answered By: Dominic Davis     Answered On: Sep 08

Thanks for the detailed explanation. This would certainly help.

I did it by programmatically adding the dataformwebpart on the page and removing
the existing listformwebpart.

Your solution is obviouly much cleaner.

Didn't find what you were looking for? Find more on SharePoint 2010 - deploying custom forms Or get search suggestion and latest updates.