About the book
This is a sample chapter of the book SharePoint 2010 Web Parts in Action. It has been published with the exclusive permission of Manning.
Written by: Wictor Wilén
Pages: 375
Publisher: ManningISBN: 9781935182771
Get 30% discount
DotNetSlacker readers can get 30% off the full print book or ebook at www.manning.com using the promo code dns30 at checkout.
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.
Exporting a Web Part
A Web Part can be exported to a Web Parts Control Description file, with the .webpart extension, which contains information about the Web Part that is exported and the current state of Web Part properties. The file is an XML file and can be viewed using Notepad or any XML editor.
You can export a Web Part from the web interface by editing the page and then use the options menu of the Web Part that you would like to export. Then choose the Export option. You will be prompted to save the file locally to your machine and the file should have .webpart file extension. This file contains XML, which describes the Web Part class and assembly to use and the default values of the Web Part properties. Once you have saved this file, you can use any text editing tool, such as Notepad or Visual Studio 2010, to change the values of the properties.
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.
.webpart or dwp file definitions?
In SharePoint 2003, the Web Parts Control Description files had the extension .dwp but, for SharePoint 2007, this changed to .webpart. They both contain XML to define the Web Part but the XML schema differs in the both. The .dwp files contains version 2 of the schema (SharePoint version 2) and the .webpart uses the version 3 of the schema (SharePoint 2007 was version 3).
If you export a Web Part based on the SharePoint implementation, then you will get a .dwp file with the version 2 of the schema instead of a .webpart file.
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.
Summary
In this article, I talked about the Web Part export and import features. I explained the steps for exporting and importing Web Parts and also how and when to prohibit users from exporting Web Parts.
Get 30% discount
DotNetSlacker readers can get 30% off the full print book or ebook at www.manning.com using the promo code dns30 at checkout.
About Manning Publications
 |
Manning Publication publishes computer books for professionals--programmers, system administrators, designers, architects, managers and others. Our focus is on computing titles at professional levels. We care about the quality of our books. We work with our authors to coax out of them the best writi...
This author has published 33 articles on DotNetSlackers. View other articles or the complete profile here.
|
You might also be interested in the following related blog posts
Using T4MVC strongly-typed helpers with Telerik Extensions for ASP.NET MVC
read more
How to Make crossdomain.xml Work with SharePoint
read more
ASP.NET 4 Web Server Here Shell Extension
read more
Make SharePoint 2007 Act Like SharePoint 2010, Updated
read more
Announcing the WebsiteSpark Program
read more
Announcing Microsoft WebsiteSpark
read more
Accessing Images On Flickr From An ASP.NET Website Using The Flickr.Net Library
read more
Announcing the Microsoft AJAX CDN
read more
Intersoft Solutions Announces WebUI Studio 2009 Service Pack 1
read more
Connect SharePoint Lists (no Web Parts) directly with external LOB data sources
read more
|
|
Please login to rate or to leave a comment.