문제

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…
도움이 되었습니까?

해결책

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();
}

다른 팁

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top