Powershell script to create a webpart page in sharepoint foundation 2010

Answered Powershell script to create a webpart page in sharepoint foundation 2010

  • Monday, July 09, 2012 1:46 PM
     
     

    Hello,

    I need to create a web part page with a given template (e.g: Full page, vertical) and add it to a library, using Sharepoint Foundation. How can I accomplish it using PowerShell?

    Thanks

    Fabrizio

All Replies

  • Monday, July 09, 2012 3:14 PM
     
     Answered

    Hi Fabrizio,

    To my knowledge there is nothing built into PowerShell that would allow you to do this.  You would have to use the Server Object Model and C# code to accomplish this.  Here are some articles that may help you out:

    http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/32ca9d61-6793-4dc9-96ff-581f22fb0528/

    http://www.etechplanet.com/blog/addingremoving-web-part-programmatically-in-sharepoint-website-using-c-code.aspx

    Also, you may want to re-post this in the developer's section of the SharePoint to see if anyone can provide you with additional information.


    -Chopps

  • Wednesday, July 11, 2012 9:39 AM
     
     Answered

    Hi,

    Please take a look at these threads create a sharepoint webpart page using Powershell


    Dmitry

    Lightning Tools LogoLightning Tools Check out our SharePoint tools and web parts | Lightning Tools Blog

  • Wednesday, July 11, 2012 9:52 AM
     
     Answered Has Code
    $web = Get-SPWeb http://server/
    $pagesLibrary = $web.GetList("Pages")
    $pageLayout = 1
    $cmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Method ID=\"0,NewWebPage\"><SetList Scope=\"Request\">" + $pagesLibrary.ID + "</SetList><SetVar Name=\"Cmd\">NewWebPage</SetVar><SetVar Name=\"ID\">New</SetVar><SetVar Name=\"Type\">WebPartPage</SetVar><SetVar Name=\"WebPartPageTemplate\">" + $pageLayout + "</SetVar><SetVar Name=\"Overwrite\">true</SetVar><SetVar Name=\"Title\">\"MyPage\"</SetVar></Method>"
    $web.ProcessBatchData($cmd)

    Available values for $pageLayout are:
    1 - Full Page, Vertical
    2 - Header, Footer, 3 Columns
    3 - Header, Left Column, Body
    4 - Header, Right Column, Body
    5 - Header, Footer, 2 Columns, 4 Rows
    6 - Header, Footer, 4 Columns, Top Row
    7 - Left Column, Header, Footer, Top Row, 3 Columns
    8 - Right Column, Header, Footer, Top Row, 3 Columns

    or here.


    My contributions: SharePoint 2010 Solution Installer


    • Edited by Aviw_ Wednesday, July 11, 2012 9:55 AM
    • Marked As Answer by Rock Wang– MSFT Friday, July 20, 2012 6:56 AM
    •