Pergunta

If you’ve got an existing page in each environment e.g. default.aspx and want to add a web part and promote to each environment what is the best approach?

  1. Create a WSP with a Feature Receiver and add to page via activation
  2. Create a WSP with a Feature and add a module with AllUserWebParts (requires deploying aspx page with it though)
  3. Manual export and import web part
  4. PowerShell script using SPLimitedWebPartManager
  5. Other…
Foi útil?

Solução

You might find the SP2010 Client Object Model usefule here. Export the Web Part to a Web Part Control Description file (.dwp or .webpart) and then flip it in like this:

using (ClientContext context = new ClientContext("http://server")) {

    Web web = context.Web;
    File file = web.GetFileByServerRelativeUrl("/SitePages/Default.aspx");
    LimitedWebPartManager wpMgr = file.GetLimitedWebPartManager(
        PersonalizationScope.Shared);

    WebPartDefinition webPartDef = wpMgr.ImportWebPart(  
        System.IO.File.ReadAllText("Content_Editor.dwp"));
    wpMgr.AddWebPart(webPartDef.WebPart, "Left", 1);

    context.ExecuteQuery();
}

Outras dicas

In the "Other" category, simply copy and paste the code from the page in one environment to the other in SharePoint Designer. It all depends on the business requirements, doesn't it?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top