This documentation is archived and is not being maintained.

WebPartManager.ImportWebPart Method

Note: This method is new in the .NET Framework version 2.0.

Imports an XML description file that contains state and property data for a WebPart control, and applies the data to the control.

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

public virtual WebPart ImportWebPart (
	XmlReader reader,
	out string errorMessage
public WebPart ImportWebPart (
	XmlReader reader, 
	/** @attribute OutAttribute() */ /** @ref */ String errorMessage
JScript does not support passing value-type arguments by reference.



An XmlReader that reads the state and property data from the XML description file that is being imported.


A String that is displayed to the user if an error is encountered during import.

Return Value

A WebPart (or a server control that is wrapped by a GenericWebPart and thus treated as a WebPart) that is referenced in the imported XML description file.

Exception typeCondition


reader is a null reference (Nothing in Visual Basic).


reader could not read the file.

- or -

reader needed to display an import error message but did not find one in the file.

- or -

reader reached the end of the file without finding the XML element that contains the exported data.

The ImportWebPart method imports an XML description file that was created by the ExportWebPart method for a server control. It is not the actual server control that is imported, but only the description file containing state and property data about the control. The control and assembly referenced in the description file must already be available on the server where a user attempts to import the description file.

To enable importing a control, a developer needs to add a CatalogZone control on the page where import will be enabled. Within the zone, an ImportCatalogPart control must be added. This control provides a file dialog box that allows users to browse and locate the description file to import.

After a user finds a description file and begins the import, the description file is read by the ImportWebPart method. If there are no errors and if the assembly and control are found, the server control is added to the catalog within the ImportCatalogPart control, and the various property and state data specified in the description file are applied to the control. The user can then select the control and add it to the page.


Like the ExportWebPart method, the ImportWebPart method has some potential for security risks. Because it involves importing data into a Web site, a malicious user could try to insert bad data or even script code into the description file that is imported. Then the bad data could appear on a page, or in a database, or the inserted script could run. For an overview of the potential risks associated with importing description files, and ways of avoiding those risks, see Securing Web Parts Pages.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0