ListViewWebPart cannot be exported by design, that’s true! ListViewWebPart elements are tied to the underlying list and views by GUID, and the GUID is unique for each view and each list in each site.
But what if you need to export it to add it to an AllUsersWebPart element in an onet.xml file ?
The following code snippet will export any web part (even if it is a ListViewWebPart ) from the page specified.
SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager(
“default.aspx”
, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); foreach(WebPart webpart in mgr.WebParts ) { string Filename = @"c:\webparts\"+ webpart.ID + ".dwp";
System.Xml.XmlTextWriter writer =
new System.Xml.XmlTextWriter(Filename,Encoding.Default);
webpart.ExportMode = System.Web.UI.WebControls. WebParts.WebPartExportMode.All; mgr.ExportWebPart(webpart, writer); writer.Close(); }