Introduction

When working with SharePoint, you most often have several environments such as development, test, staging, and production to secure and validate your implementation. You start by building and configuring your Web Parts in the development environment before moving on to the test, and so on. If you have a Web Part with a lot of configuration options and would like to move that into another environment, it can be hard to reconfigure the Web Part in the new site. This is especially important in Application Lifecycle Management scenarios when you are scripting your environments and configurations.

In this article, you will learn how to export and import a configured Web Part and how to prohibit users from exporting a Web Part. You will find this valuable as you start developing your Web Parts. You will save significant time if you export the Web Parts instead of manually typing everything.

Importing a Web Part

If you have a Web Parts Control Description file (a .webpart file) that you either created yourself or received from someone else, you can upload this definition to the Web Part Gallery. Note that, in order to get the Web Part to work, you need to have the corresponding Web Part assembly installed in your environment; otherwise, the Web Part will fail with an error message.

To add a Web Part to the gallery using a .webpart file you have to go to the Web Part gallery and upload the file using the Library Tools > Documents tab. Once the file is uploaded, you need to specify metadata on the Web Part such as title, description, and group, just like you do on any item that is added or uploaded into SharePoint.

You can add a pre-configured Web Part to a page without uploading it to the Web Part Gallery. This is achieved using the Ribbon toolbar to add a new Web Part. When the Web Part gallery shows up in the interface, you need to click Upload a Web Part under the Categories list. This Web Part will appear in the Imported Web Parts category and can then be added to the page. This uploaded Web Part configuration is only temporarily available in the gallery to the user editing the specific page and will not be available once you exit edit mode.

Prohibiting the export of a Web Part

You will find yourself in situations when you do not want the users to be able to export your Web Parts; it might store confidential data in properties or there might be other reasons. Web Parts have a property called Export Mode, which defines how a Web Part can be exported. It can have one of the following values

– Do not allow
– Non-sensitive data only
– Export all data

You can access this property by editing the Web Part properties and change the value of the Export Mode property under the Advanced category.