简体   繁体   中英

How can I add WebPart on Sharepoint WikiPage?

How can I add WebPart on Sharepoint WikiPage?

For example: How can I add GettingStartedWebPart on Sharepoint 2013 home page (SitePages/Home.aspx)?

I used "Team Site" template for my Site Collection. And removed default "Get started with your site" web part.

I am trying:

...
SPLimitedWebPartManager spLimitedWebPartManager = spFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
var gettingStartedWebPart = new GettingStartedWebPart();
....
spLimitedWebPartManager.AddWebPart(gettingStartedWebPart, "wpz", 0);

But it doesn't work. Do you have any idea how to do it? Thank you for your time :) and solutions.

Edit:

I found the solution. First of all, you can use standard method for "Wiki Page" WikiEditPage.InsertWebPartIntoWikiPage. But, this method doesn't work correctly... More of this and one of the possible fix you can find if you read this article about SharePoint 2010 (The realization of WikiEditPage.InsertWebPartIntoWikiPage in SharePoint 2013 is the same as in SharePoint 2010): http://habaneroconsulting.com/insights/programmatically-change-content-on-a-wiki-page-in-sharepoint-2010#.VgAEAfmqpBd .

Also: http://maxshulga.blogspot.com/2010/06/wikieditpageinsertwebpartintowikipage.html

I've done something like this in the past with

private void AddWebPartToPage(SPWeb web, string filepath, string zoneidname, int zoneIndex)
    {
        SPLimitedWebPartManager wpm = web.GetLimitedWebPartManager(filepath, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

        wpm.AddWebPart(wp, zoneidname, zoneIndex);


    }

AddWebPartToPage(web, web.Url + "SitePages/Home.aspx", "CentreLeft", 0);

You will need to test this though.

Hope this helps.

Cheers Truez

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM