WebPartManager.ExportWebPart Method (WebPart, XmlWriter)


Creates an XML description file that contains state and property data for a server control.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

public virtual void ExportWebPart(
	WebPart webPart,
	XmlWriter writer


Type: System.Web.UI.WebControls.WebParts.WebPart

The control from which data will be exported.

Type: System.Xml.XmlWriter

An XmlWriter that writes the exported data from webPart to an XML description file.

Exception Condition

webPart is null.

- or -

writer is null.


webPart is not contained in the collection of controls referenced in Controls.

- or -

The ExportMode property of webPart is set to a value of None, which means that export is disabled for webPart.

The ExportWebPart method assembles various state and property data from webPart into an XML file. The data includes information about the control itself, including its assembly, state data, and property data. The user who initiates the export can save the XML file to disk on the local computer or the network. Other users can then import the description file to a different page or Web site, and apply the state and property data to a different instance of webPart. This provides a fast and convenient mechanism for users to share and reuse their settings on server controls, and it also provides developers with a means to control the appearance and behavior of exported and imported controls.

Properties on webPart are not exported by default. To enable export of a property, you must mark it with the [Personalizable] attribute in the source code. You can also optionally mark an exportable property as containing sensitive data, by setting the isSensitive parameter of the [Personalizable] attribute to true. By default, isSensitive is false. Developers can set the parameter to true to indicate that the data is sensitive.

To enable webPart to be exported, a developer sets its ExportMode property value to either All (which includes all personalizable and sensitive properties), or to NonSensitiveData, which exports everything except for sensitive properties.


Allowing users to export data from controls, and to import data into other controls, entails some security risks. Developers should use the approach discussed above to protect sensitive data, and if they want to avoid the risk of exposing data altogether, they should not enable export on webPart at all. For details on Web Parts security issues, see Securing Web Parts Pages.

.NET Framework
Available since 2.0
Return to top