SPLimitedWebPartManager.ImportWebPart Method (Microsoft.SharePoint.WebPartPages)
Imports an XML description file (*.dwp or *.webpart) that contains state and property data for a Web Part, and applies the data to the Web Part.

Namespace: Microsoft.SharePoint.WebPartPages
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
Public Function ImportWebPart ( _
    reader As XmlReader, _
    <OutAttribute> ByRef errorMessage As String _
) As WebPart
Visual Basic (Usage)
Dim instance As SPLimitedWebPartManager
Dim reader As XmlReader
Dim errorMessage As String
Dim returnValue As WebPart

returnValue = instance.ImportWebPart(reader, errorMessage)
C#
public WebPart ImportWebPart (
    XmlReader reader,
    out string errorMessage
)

Parameters

reader

errorMessage

See Also

Tags :


Community Content

WagsWVU
Importing WebPart Using SPLimitedWebPartManager.ImportWebPart

I had a hard time finding exactly what I needed to do in order to import a .dwp programmatically in MOSS 07. Below is some sample code:

SPLimitedWebPartManager mgr;
mgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
XmlReader oxmlReader = new XmlTextReader(" THE PATH TO YOUR DWP FILE ");
System.Web.UI.WebControls.WebParts.WebPart oWebPart = mgr.ImportWebPart(oxmlReader, out ErrorMessage);
mgr.AddWebPart(oWebPart, "WEBPART ZONE", ZONE INDEX);  

Hope that Helps.


jab_be
Define zone in dwp file not possible
I try the same code but zone is defined in dwp file (tags ZoneId and ZoneIndex)
mgr.AddWebPart(oWebPart, oWebPart.Zone.ID, oWebPArt.ZoneIndex);  
But unfortunatelly, oWebPart.Zone is always null and oWebPArt.ZoneIndex is always 1.

Tags :

Page view tracker