Thursday 17 May 2007

SharePoint 2007: Solving the List GUID Export Problem

In a previous post I blogged about the fact that when creating a custom DataSource using SharePoint Designer, the SelectParameters by default reference the ListId and then specifically the GUID. This creates a problem when exporting your customised page, since the ListId you reference will be lost and thus your DataSource will be practically useless.

Its seems that other people have been experiencing the same problem including Ishai who developed custom code to workaround the problem. In the same post, Donal mentioned that you can use the List Name rather than the Guid. This was obviously too much to resist, and I spent some time trying looking around to try and solve this problem. I came across this post SPDataSource and Rollups with the Data View. One of the comments said that besides the List Id you can also use the listname as a parameter to the Data Source. Therefore I modified my datasources such that they were similar to the below.

<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="<View></View>" id="Announcements1">
<SelectParameters>
<WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Announcements"/>
</SelectParameters>
</SharePoint:SPDataSource>

<ParameterBinding Name="ListName" Location="None" DefaultValue="Announcements"/>

I saved the page, transferred it to another server which had the same lists, executed the page and voila! the problem was solved!