I am deploying a list using Visual Studio 2010 that is based on a content type I created. The list also uses custom new/edit/display forms whcih I created using SharePoint Designer. I achieve this all as follows:

<?xml version="1.0" encoding="utf-8"?> 
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
    <ContentType ID="0x0100730B35B9AD3755498EF8D60B1E3E0AFE01" 
                 Name="Custom Content Type" 
            // Code omitted for readability 
            <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url"> 
                <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url"> 

Note the FormUrls section -- this instructs SharePoint to always load the specified form for this content type (as appposed to the default OOTB list forms). See MSDN.

To create my custom forms, I simply created a copy of the OOTB "NewForm.aspx" file and tweaked the layout a little. Nothing drastic.

So far this all works great.

My only problem is that "NewForm.aspx" contains some hardcoded list ID and URL references which I need to replace (with a token?). An example is in the SPDataSource control:

    <SharePoint:SPDataSource runat="server" DataSourceMode="ListItem" SelectCommand="..." UseInternalName="True" UseServerDataFormat="True">
            <WebPartPages:DataFormParameter ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0" Name="ListItemId"></WebPartPages:DataFormParameter>
            <WebPartPages:DataFormParameter ParameterKey="weburl" PropertyName="ParameterValues" DefaultValue="http://devsite" Name="weburl"></WebPartPages:DataFormParameter>
            <WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{40047E88-C8E1-4E9B-88E6-2FD75A9D8533}" Name="ListID"></WebPartPages:DataFormParameter>

What can I replace the hardcoded URL and ListID paramter values with so that my custom form will work with any list that is based on this content type in the future?

1 Answer 1


It seems you can't use tokens as such, but you can change the default parameters slightly to more reusable ones... e.g:

I changed the WebUrl parameter to:

<WebPartPages:DataFormParameter ParameterKey="weburl" PropertyName="ParameterValues" DefaultValue="/" Name="weburl"></WebPartPages:DataFormParameter> 

And the ListID parameter to:

<WebPartPages:DataFormParameter ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Plant Compliance Inspection" Name="ListName"></WebPartPages:DataFormParameter>

As you can see, I have referenced the list by name instead of ID. Admittedly, this does still "hardcode" you to a specific list, but it at least prevents your forms from breaking every time you just re-deploy from Visual Studio (as it blows away your list and recreates it, thus creating a new GUID).

See http://sympmarc.com/2008/12/16/replacing-listids-with-listnames-in-data-view-web-parts/ for more details.

I hope this helps somebody. This stole an entire day out of my life.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.