MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

Copy a webpart programmatically

  Asked By: Raven    Date: Feb 16    Category: MOSS    Views: 2230

I have a client that wants to copy an existing webpart from an
existing MOSS 07 page and add that webpart to the "MySite" page.

I know I can use something like this to add a webpart to a page as
long as I have access to the *.webpart or *.dwp file:
public void AddWebPart2()
string err = string.Empty;
string chromeType = "Default";
string zoneIndex = "Left";
string Error = string.Empty;

using (SPSite site = new SPSite("http://ford/test"))
using (SPWeb web = site.OpenWeb())
SPFile file = web.GetFile("default.aspx");

SPLimitedWebPartManager manager1 =
XmlReader reader1 = GetWebPartDef
part1 = manager1.ImportWebPart(reader1, out err);
part1.ChromeType = (PartChromeType)Enum.Parse
(typeof(PartChromeType), chromeType);
manager1.AddWebPart(part1, zoneIndex, 1);
catch (Exception ex)
Error = "AddWebPart2 Error: " + ex.Message;
throw new Exception(Error);

} // End of using web

} // End of using site

So my question is ... how can I get the *.webpart or *.dwp file from
the webpart gallery? Or do I get it from the webpart gallery? If
not where can I gain access to these/this file from?



1 Answer Found

Answer #1    Answered By: Tyrell Nash     Answered On: Feb 16

Can you go to the page  where the webpart  is used and then export that
webpart via "edit page" ->"edit shared  webpart"?

Didn't find what you were looking for? Find more on Copy a webpart programmatically Or get search suggestion and latest updates.