This topic has not yet been rated - Rate this topic

WikiEditPage.InsertWebPartIntoWikiPage Method

SharePoint 2010

Inserts a WebPart at a specified position of a wiki page.

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
public static void InsertWebPartIntoWikiPage(
	SPFile wikiFile,
	WebPart webpart,
	int position
)

Parameters

wikiFile
Type: Microsoft.SharePoint.SPFile
The wiki page in which the WebPart will be inserted.
webpart
Type: System.Web.UI.WebControls.WebParts.WebPart
The WebPart to be inserted.
position
Type: System.Int32
The position in the wiki of the specified page.

The WebPart is inserted as a part of the content of the wiki in the specified page.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Code to Add a Webpart on the Wiki Home Page
 using (SPSite site = new SPSite("SiteUrl"))
            {
                using (SPWeb web = site.OpenWeb("/Departments/IT"))
                {

                    SPList announcementsList = web.Lists["Announcements"];
                    ListViewWebPart announcementsWebPart = new ListViewWebPart();
                    announcementsWebPart = new ListViewWebPart();
                    announcementsWebPart.Title = announcementsList.Title;
                    announcementsWebPart.ListName = announcementsList.ID.ToString().ToUpper();
                    announcementsWebPart.TitleUrl = announcementsList.DefaultViewUrl;
                    announcementsWebPart.ViewGuid = announcementsList.DefaultView.ID.ToString().ToUpper();

                    SPFile file = web.GetFile(web.ServerRelativeUrl + "/sitepages/home.aspx");
                    web.AllowUnsafeUpdates = true;
                    WikiEditPage.InsertWebPartIntoWikiPage(file, announcementsWebPart, 3);
                    web.AllowUnsafeUpdates = false;

                }


            }