This post is migrated from previous hosting provider. There are still some issues with old posts. Please make a comment on this post with any issues.

How to export and reuse the Data View Web Part

Tags: SharePoint, Web Parts

Inspired by the latest SharePoint PodShow topic; The SharePoint Data View Web Part-Episode 31 and Laura Rogers post on building a permissions dashboard I just had to write this post. In the last paragraph Laura quickly mentions how you can reuse the created Data View Web Part. I think this is really important to know how to export and import this Web Part. What I don't want people to do is to fire up SharePoint Designer and create these Data View Web Parts in the production environment so that the pages get's unghosted or customized. Also when you are working with solutions packages and features to deploy your applications in environments it's necessary to know how to do this.

Exporting

Once you have created and finalized your Data View Web Part in your development environment or sandbox, then you can export your customizations. This is the same for all kinds of Web Parts, as long as they allow exporting. When you export a Web Part through the web interface you will get a .webpart file (read earlier published post on this), containing all the properties and metadata specified for the Web Part.

Export... Just open the Web Part menu on the Web Part and select Export... to export the Web Part. You will be prompted for a location to save the file.

Once you saved it you will have a nnn.webpart file on your disk, which essentially is an XML file with the metadata.

Note: Your exported Web Part will contain the exact properties as you specified in your original location. For example if you connected to it to a list this list id will not be present in the location where you import it. So before importing it you might have to change some values in the .webpart file or at least edit the properties of the Web Part after uploading it.

Importing to the Web Part Gallery

If you have created a Data View Web Part that you will reuse many times throughout a Site Collection it might be worth uploading it to the Web Part Gallery. Just go to the Site Settings and then the Web Part Gallery and select Upload and upload your .webpart file. After this your Web Part is available for all authors to use.

Importing to a page

Advanced Web Part gallery options Importing the Web Part is not that difficult, though it can be hard to find where to do it. To import the Web Part, go to the page where you want to insert it and edit the page and then choose to add a new Web Part. Then you have to select Advanced Web Part gallery options, located in the lower right corner. When the page is re-loaded click on the Browse header and choose Import.

Find the Import functionality... One Web Part imported

After that you can click on Browse to select your .webpart file and finally click Upload. Once the upload is done the Web Part will appear and you can drag and drop it onto your Web Part page.

Once it is on the page you may have to edit the properties of the Data View Web Part. You might have to change the data sources, if you for instance configured your Data View Web Part to work with a certain Site id or a List id.

Using the Web Part in features

You can also reuse this exported .webpart file in your SharePoint features and have them added to the Web Part gallery when activating the feature.

Another scenario, which I've used to build dashboards and dashboard sites is that you use the SPLimitedWebPartManager to create dashboards on feature activations or certain events. The SPLimitedWebPartManager has an ImportWebPart method that takes an XmlReader as input, which essentially is your .webpart file.

I hope you got something interesting out of this and if you haven't listened to the SharePoint PodShow about the Data View Web Part - do that immediately and understand the power of it!

2 Comments

  • Paul said

    Hi, thanks for this article. I have managed to successfully export my data view webpart. It was located on my sandbox/development server. Just a couple of columns of metadata in a list which I styled the layout etc.. when I import it though to my staging enviroment, I open the parameters box and change the list ID to the new list I created it behaves strangely. First it says it cannot display it properly. Then when I publish the page, it seems that the items in my list are blanked out in white and it is blank.. just wonder if there are specific parts of the XML I have to alter as I have scanned it and cannot see anything that points/relates to the development server

Comments have been disabled for this content.

About Wictor...

Wictor Wilén is the Nordic Digital Workplace Lead working at Avanade. Wictor has achieved the Microsoft Certified Architect (MCA) - SharePoint 2010, Microsoft Certified Solutions Master (MCSM) - SharePoint  and Microsoft Certified Master (MCM) - SharePoint 2010 certifications. He has also been awarded Microsoft Most Valuable Professional (MVP) for seven consecutive years.

And a word from our sponsors...