MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

Error with ImportWebPart

  Asked By: Deepak    Date: Dec 19    Category: MOSS    Views: 3154

I am trying to add a webpart into a MOSS site, however, ImportWebPart
throws an exception everytime I try to import the webpart part.

string URL = "http://servername/_catalogs/wp/MSContentEditor.dwp";

WebClient webClient = new WebClient();
NetworkCredential myCred = new NetworkCredential
("username", "password", "domain");

webClient.Credentials = myCred;
System.IO.StringReader oReader = new StringReader(URL);
XmlReader oXmlReader = new XmlTextReader(oReader);

mySiteWeb.AllowUnsafeUpdates = true;

SPFile file = mySiteWeb.GetFile("default.aspx");
SPLimitedWebPartManager WebPartMgr = file.GetLimitedWebPartManager

// import the webpart (*.dwp or *.webpart) into the a newly
created WebPart object
string errMsg = "";

System.Web.UI.WebControls.WebParts.WebPart webpart =
WebPartMgr.ImportWebPart(oXmlReader, out errMsg);

// add the webpart to the MySite
WebPartMgr.AddWebPart(webpart, "Left", 1);

// copy completed
mySiteWeb.AllowUnsafeUpdates = false;

Throws this error on ImportWebPart..."The file you imported is not
valid. Verify that the file is a Web Part description file (*.webpart
or *.dwp) and that it contains well-formed XML."

I know the file is good...content of webpart file:

<?xml version="1.0" encoding="utf-8" ?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
<Assembly>Microsoft.SharePoint, Version=, Culture=neutral,

<Title>Content Editor Web Part</Title>
<Description>Use for formatted text, tables, and

This is the ContentEditor webpart from MOSS. I have tried many other
*.dwp and *.webpart files.

Any thoughts?



3 Answers Found

Answer #1    Answered By: Kacey Russo     Answered On: Dec 19

Are you importing it into a MOSS environment or a WSS environment? The
.dwp is not actually the webpart, its just an XML that specifies what
.dll contains the class that is the web  part. If the .dll isn't on the
server the webpart  can't be imported.

Answer #2    Answered By: Rebecca Lewis     Answered On: Dec 19

I am trying to import  the webpart  into a MOSS environment. I am reading the
file from the webpart gallery and I want to programmatically add  the webpart
to another MOSS site. I thought the *.dwp or the *.webpart file  is what
ImportWebPart needed. Is this not correct? The webpart is in the webpart
gallery therefore the *.dll is on the server.

Answer #3    Answered By: Developer Network     Answered On: Sep 07
Didn't find what you were looking for? Find more on Error with ImportWebPart Or get search suggestion and latest updates.