Programmatically instantiate a web part page in Sharepoint

前端 未结 3 1092
说谎
说谎 2020-12-29 14:44

Is there a simple way to add a web part page to a Sharepoint site programmatically, using either the object model or web services? It seems straight-forward to create lists

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 15:01

    An alternative solution to the accepted answer from @AlexAngas is to use the NewWebPage method of the SharePoint Foundation RPC Protocol, as suggested here.

    private static void CreateWebPartPage(this SPWeb web, SPList list, string pageName, int layoutTemplate)
    {
        const string newWPPage = "" +
                                       "" +
                                       "" +
                                        "{0}" +
                                        "NewWebPage" +
                                        "New" +
                                        "WebPartPage" +
                                        "{2}" +
                                        "true" +
                                        "{1}" +
                                        "" +
                                         "";
        var newWPPageBatchXml = string.Format(newWPPage, list.ID, pageName, layoutTemplate);
    
        var result = web.ProcessBatchData(newWPPageBatchXml);
    }
    

    Usage of the above extension method:

    web.CreateWebPartPage(yourList, "NewPage", 2);
    

提交回复
热议问题