Just little about C#, .NET, SQL Server, SharePoint and SAP

Updating List ID values in DataFormWebPart after import operation

Posted by zieglers on January 29, 2009

For the last couple of months, I’ve been developing some POC SharePoint VPCs for clients. Mostly they were publishing sites with lots of UI and functionality customization. Once the development was over, I had to prepare deployment packages for delivery to client environment.

At this point I had mainly two choices for deployment. I could either do export – import operation, or develop features for creating publishing site, custom lists, master pages, layouts and web parts. I’ve tried both approaches and they have their own pros and cons. However, what I’d like to mention in this post is updating list ids.

Doesn’t matter which approach I took, every time I had to update List ID values of content query web parts and dataform web parts. The reason is List ID values in those web parts were still pointing to exported site’s List GUDs.

Manually updating those values is a solution, however it’s time consuming and not practical after importing a number of sites. After some reseach and trials, finally I figured out how to update List IDs automatically.

In order to achieve this, I’m using two main tools:

1. Gary Lapointe’s stsadm extensions: replacewebpartcontent command for replacing old List ID value with new one



Download and install Stsadm Extensions from Gary Lapointe’s blog: http://stsadm.blogspot.com/

2. PowerShell scripting: getting new List ID after importing the site or activating feature which creates custom lists used in the site.

Ok, now let’s get our hands dirty…

1. Introduction

Scenario is as follows: We have imported our sample publishing site and necessary lists have been created. You go to the site and see the error messages in dataform web parts saying that:

“Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”

Say, we have a sample web part named MyDataFormWP on home page of the site. Also this dataform web part is using our sample list named MySampleList. Also let’s assume that just imported publishing site hosted at this url: http://myservername:1000.

2. Getting new List ID using PowerShell

(If you haven’t done so yet, download PowerShell from Microsoft Download Center and install it.)

At this point I need to know the list id of recently created MySampleList. This is going to be passed to replacewebpartcontent command as a replacestring parameter. In order to do so, “SharePoint should be ready to take off…” 🙂 What this means is explained in this article: http://cglessner.blogspot.com/2008/06/powershell-sharepoint.html 

You can also download this profile file from: http://www.codeplex.com/iLoveSharePoint/Release/ProjectReleases.aspx?ReleaseId=14994


Once you apply the steps explained in the above article and set up your powershell profile for sharepoint, now you can easily get the List ID of lists you want.

Just run these two lines:

$list = get-splist -webUrl http://myservername:1000 -listName MySampleList


Now, we now our new list ID and ready to pass this as parameter to replacewebpartcontent command.

3. Replacing List ID value in DataForm Web Part

Here is the syntax of replacewebpartcontent command’s usage:

stsadm -o gl-replacewebpartcontent -url http://myservername:1000/HomePage.aspx -webpartname MyDataFormWP -searchstring “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx” -replacestring $list.ID -publish -scope page

url parameter: web page url hosting our sample web part

-webpartname parameter: obviously the name of web part whose list id we would like to update

-searchstring parameter: old list id. This is the only static parameter that we need to provide to this command. You can find old list id by exporting the web part on the page and searching for List ID value in it.

-replacestring parameter: This is our new list id which we obtained above using PowerShell commands.

4. Putting it all together: Passing webUrl as parameter to PowerShell script

Until now all steps explained above are individual automations. We can put everything together into a PowerShell script. Here is a sample one: MyScript.ps1

=== MyScript.ps1 ===


$list = get-splist -webUrl $webUrl -listName MySampleList
stsadm -o gl-replacewebpartcontent -url $webUrl/HomePage.aspx -webpartname MyDataFormWP -searchstring xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -replacestring $list.ID -publish -scope page


To execute this script (assuming MyScript.ps1 file is in the same folder), simply run the following command from Command Prompt:

PowerShell -command .\MyScript.ps1 -webUrl http://myservername:1000

That’s all… 🙂 Hope it works for you as well..

There are couple of enhancements to do here as well.

1. Search string (old list ID) can be found automatically

2. Web part names or old list ids can be read from an input file or passed as other parameters.

I’ll try to enhance this approach once I have more time to spend on it. As for now, this much automation works for my deployment scenarios. Please feel free to share any comments, ideas or other possible approaches.


One Response to “Updating List ID values in DataFormWebPart after import operation”

  1. review said


    […]Updating List ID values in DataFormWebPart after import operation « Zieglers[…]…

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: