public void InsertWebPartIntoWikiPage(SPFile wikiFile, System.Web.UI.WebControls.WebParts.WebPart webpart, string replaceToken)
        {
            wikiFile.RequireNotNull("wikiFile");
            webpart.RequireNotNull("webpart");
            string str = (string)wikiFile.Item["WikiField"];

            using (SPLimitedWebPartManager limitedWebPartManager = wikiFile.GetLimitedWebPartManager(PersonalizationScope.Shared))
            {
                Guid storageKey = Guid.NewGuid();
                string str2 = StorageKeyToID(storageKey);
                webpart.ID = str2;
                limitedWebPartManager.AddWebPart(webpart, "wpz", 0);
                string str3 = string.Format(CultureInfo.InvariantCulture, "<div class='ms-rtestate-read ms-rte-wpbox' contentEditable='false'><div class='ms-rtestate-read {0}' id='div_{0}'></div><div style='display:none' id='vid_{0}'/></div>",
                                            new object[]
                                        {
                                            storageKey.ToString("D")
                                        });
                if (str == null)
                {
                    str = str3;
                }
                else
                {
                    if (!str.Contains(replaceToken))
                    {
                        str = str + str3;
                    }
                    else
                    {
                        str = str.Replace(replaceToken, str3);
                    }
                }
                wikiFile.Item["WikiField"] = str; wikiFile.Item.Update();
            }
        }
        public static void AddWebPart(SPLimitedWebPartManager webPartManager, System.Web.UI.WebControls.WebParts.WebPart webPart, string zone, int zoneIndex, PartChromeType chromeType, string accesskey)
        {
            webPartManager.RequireNotNull("webPartManager");
            webPart.RequireNotNull("webPart");
            zone.RequireNotNullOrEmpty("zone");
            zoneIndex.Require(zoneIndex >= 0, "zoneIndex");

            webPart.AccessKey = accesskey;
            webPart.ChromeType = chromeType;
            webPartManager.AddWebPart(webPart, zone, zoneIndex);
            webPartManager.SaveChanges(webPart);
        }