WebPartManager.ImportWebPart(XmlReader, String) Method

Definition

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

public:
 virtual System::Web::UI::WebControls::WebParts::WebPart ^ ImportWebPart(System::Xml::XmlReader ^ reader, [Runtime::InteropServices::Out] System::String ^ % errorMessage);
public virtual System.Web.UI.WebControls.WebParts.WebPart ImportWebPart (System.Xml.XmlReader reader, out string errorMessage);
abstract member ImportWebPart : System.Xml.XmlReader * string -> System.Web.UI.WebControls.WebParts.WebPart
override this.ImportWebPart : System.Xml.XmlReader * string -> System.Web.UI.WebControls.WebParts.WebPart
Public Overridable Function ImportWebPart (reader As XmlReader, ByRef errorMessage As String) As WebPart

Parameters

reader
XmlReader

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

errorMessage
String

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

Returns

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.

Exceptions

reader is null.

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.

Remarks

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.

Important

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.

Applies to

See also