SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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=""> 
    <ContentType ID="0x0100730B35B9AD3755498EF8D60B1E3E0AFE01" 
                 Name="Custom Content Type" 
            // Code omitted for readability 
            <XmlDocument NamespaceURI=""> 
                <FormUrls xmlns=""> 

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?

share|improve this question
up vote 1 down vote accepted

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 for more details.

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.