Click to Rate and Give Feedback

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
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)
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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Importing WebPart Using SPLimitedWebPartManager.ImportWebPart      WagsWVU   |   Edit   |   Show History

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.

Define zone in dwp file not possible      jab_be   |   Edit   |   Show History
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 What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker