Thursday, February 21, 2008

Saving site as a site template with DataView WebPart

As most of us know that if you create a site out of a custom site template with DataView Web Part on it, the DataView Web Part pages of this site are not going to display properly.

The Error presented in the browser will be like this:
“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.”

When SP creates the site, it recreates lists, thus assigning a brand new GUID to it.

Sure enough if you open the page in SharePoint designer you will see that the DataVIew Web Part has lost it’s data source because it still refers to the original list’s GUID that it was bound to. But there is a way to avoid this.
And, no, I’m not going to take all the credits for this tip, as it was generously given to me by my colleague, Jonathan Bradshaw (Thank you J).

You can preserve the DataView Web Part data source by binding it not to the GUID of your list but to the List Name instead:

• Open the web part definition in your editor of choice
• Look for all occurrences of ListID in the web part definition and right next to that you should see a GUID.
• Replace ListID with ListName and the GUID with the list name you want to bind to.

It’s that easy.

22 comments:

Anonymous said...

Actually, I wanted to ask a question about your article "Training Classes Scheduling Solution " but could not find a place there to post it.

I followed your information step-by-step, but when I add the "concat)" and "ClassID=’,@ID,’}__redirect={MyClasses.aspx}')" to my javascript, it throws an error: (Failed Setting processor stylesheet: 0x80004005: Invalid number of arguments.

This error makes no sense to me, and I am hoping you know what it means:)

I have been working with SharePoint for 8 months now and haven't had too much experience with WorkFlows.

Natalya Voskresenskaya [SharePoint MVP] said...

Send me the whole javascript thing, I'll take a look at it.
here is the link for comments regarding this article http://spforsquirrels.blogspot.com/2008/02/sharepoint-beagle-articles.html

Anonymous said...

That works great! I can not believe how easy that was.

Mark Smith said...

Is there away to format the dataview to that when you make a site template the issue does not come back. I was hoping I could take a library called "Stocks" and then change the list id to "Stocks" also, but that doesn't work and I really wish it did. Then I could have site templates to share using the dataview webpart and not the built in webparts. Nice post by the way.

Anonymous said...

Hmmm...
This substitute generates an error when you open data source of the DataView in the SPDesigner, so be aware :)
The reason why it happens because the ListID is used as a parameter to query the list.

Natalya Voskresenskaya [SharePoint MVP] said...

OK, here is the sample code:

Original"
<WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="1D4999B9-91A6-46D6-89C4-45E8B0AF4908"/>
Modified to:
<WebPartPages:DataFormParameter PropertyName="ParameterValues" ParameterKey="ListID" DefaultValue="Classes" Name="ListName">



Original:
<ParameterBinding Name="ListID" Location="None" DefaultValue="1D4999B9-91A6-46D6-89C4-45E8B0AF4908"/>
Modified to:
<ParameterBinding Name="ListID" Location="None" DefaultValue="Classes"/>

I just want to make sure you are not modifying wrong parameters

Gus said...

Hi Natalya,

I have a question:
I have a Content Editor Web Part with embedded Windows Media Player streaming media from video clips in a picture library. I used the code from here: http://www.wssdemo.com/Pages/video/video.aspx

However at this point I had to create a separate page for each clip. I suspect that there is a method that could be used in linking the Image Library items in one WebPart feeding the Video Control in a separate WebPart. I am not certain how one could accomplish this and was wondering if you could give some guidance on possibilities.

Thank You,
Gus

Natalya Voskresenskaya [SharePoint MVP] said...

I did not try it yet, but I would suspect that you can use filter webpart on a sigle page containing the video player to pass video file name into the URL of the page.
In you content editor WP obtain this URL through javascript.

Gus said...

Thank you so much for responding so quickly..

Since I am not a Java programmer, can you give me some links as to where I could learn how to do this?

Natalya Voskresenskaya [SharePoint MVP] said...

There are many resources for javascript. this one might be worth checking out http://www.w3schools.com/htmldom/dom_reference.asp. the Idea is to have a filter webpart based on you library and pass the selected video parameters through the URL onto the same page. in the javascript parse it to extract the parameter and construct the right URL to imbed into the object. I'll test it out and maybe blog about it :-)

Anonymous said...

Hi,
I need help with a DataView: I Want to Export it to a web part gallery and import it to another site. I have replaced "ListID" with "ListName", and the GUID with the list name. But, now it stops. I still got a error when I try to add the web part to another site. I hope you can look at my code and tell me what to do further...

Natalya Voskresenskaya [SharePoint MVP] said...

THe site where you want to import this web part to must have this list with the same name already created there. if it still does not work send me your code.

Anonymous said...

So in your previous comment/answer, you are saying that the list from which the data view is pulling must exist within the site that the data view exists in or can the dataview pull from another list on another site/subsite...?

Anonymous said...

Thank you for your post Natalya. I think it may be the answer to my problem, if I can get it working.

My list name for my dataview is: AssessmentData (It was 'AssessmentData' when I first created it but I since changed it to 'Assessment Data' - but I think kit still keeps its original name 'Assessment Data' - is this correct?)

Anyway, I tried pasting my code in this comment but I am not allowed to use tags... So here is a link to a txt file with the code that I have updated on my site according to your instructions:
http://www.tech-savvy.com.au/www/images/stories/dataviewcode.txt

I am still getting the error ("The server returned a non-specific error when trying to get data from the data source. Check the format and content of your query and try again. If the problem persists, contact the server administrator").

Could you please let me know what I need to change? I would really appreciate your help :)

... If there are no errors, is there a chance I might have the list name wrong? How can I check the registered list name?

Natalya Voskresenskaya [SharePoint MVP] said...

Krysty,
replace "ParameterKey="ListID" with ParameterKey="ListName"
Let me know if you still have this problem :-)

Natalya Voskresenskaya [SharePoint MVP] said...

Krysty,
replace "ParameterKey="ListID" with ParameterKey="ListName"
Let me know if you still have this problem :-)

Natalya Voskresenskaya [SharePoint MVP] said...

To all, I can see how this can get confusing as in one of my comments I've made a mistake
<ParameterBinding Name="ListID" Location="None" DefaultValue="1D4999B9-91A6-46D6-89C4-45E8B0AF4908"/>
Modified to:
<ParameterBinding Name="ListID" Location="None" DefaultValue="Classes"/>
Last line should read
<ParameterBinding Name="ListName" Location="None" DefaultValue="Classes"/>

Anonymous said...

Hi Natalya,

Thanks for your advice. I have changed the code but it is still not working for me. Here is a copy ofthe code I currently have:
http://www.tech-savvy.com.au/www/images/stories/parameterbinding.txt

Can you let me know if you can spot any mistakes?

Thank-you again!

Natalya Voskresenskaya [SharePoint MVP] said...

Kristie, you still have one line that you have overlooked

<SelectParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="00FF2CDC-3A67-4194-93DA-76CB84EADDA2" Name="ListID">

replace it with

<SelectParameters><WebPartPages:DataFormParameter ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="AssessmentData" Name="ListName">

Anonymous said...

Thanks a bunch.

Anonymous said...

Thank you so much, Natalya!! It worked!! I am creating a database for our network of schools to be able to track student results and therefore design curriculum to meet the needs of their specific students. Your assistance has been invaluable in helping me to achieve this goal! When the database is complete, I will make it available online to any teacher who wishes to use it, and I will give credit to you with a link to your blog. I really appreciate you taking the time to help out newbies like me! :)

Anonymous said...

Hi Natalya,

I am using a Linked Data source(After Linking 2 Lists).

So how will this idea work in my case? Please let me know.