我正在遵循此内容(http://msdn.microsoft.com/en-us/library/ms450826.aspx)方法来添加webpartpage(samplewpp.aspx),并且可以正常工作。但是,我还需要添加一个行描述。如何?

没有正确的解决方案

其他提示

您需要将内容编辑器Web部件(CEWP)添加到页面上,然后将您的描述添加到此处。 CEWP允许您将文本/HTML放在页面上。

以编程方式进行此操作然后遵循 像Razi Bin Rais的此代码一样 :-

AddAndFillCEWP("http://server","/" ,"/Pages/blank.aspx","this text is adding via    code","Header","CEWP WebPart");

private void AddAndFillCEWP(string siteUrl, string webName, string pageUrl, string textCEWP, string zoneId, string title)
{
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite spSiteTest = new SPSite(siteUrl))
        {
            using (SPWeb web = spSiteTest.OpenWeb(webName))
            {
                try
                {
                    web.AllowUnsafeUpdates = true;
                    SPFile file = web.GetFile(pageUrl);
                    if (null != file)
                    {
                        using (SPLimitedWebPartManager mgr = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
                        {
                            if (null != mgr)
                            {
                                //create new webpart object            
                                ContentEditorWebPart contentEditor = new ContentEditorWebPart();

                                //set properties of new webpart object     
                                contentEditor.ZoneID = zoneId;
                                contentEditor.Title = title;
                                contentEditor.ChromeState = System.Web.UI.WebControls.WebParts.PartChromeState.Normal;
                                contentEditor.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.TitleAndBorder;

                                //Add content to CEWP
                                XmlDocument xmlDoc = new XmlDocument();
                                XmlElement xmlElement = xmlDoc.CreateElement("Root");
                                xmlElement.InnerText = textCEWP;
                                contentEditor.Content = xmlElement;
                                contentEditor.Content.InnerText = xmlElement.InnerText;

                                //Add it to the zone
                                mgr.AddWebPart(contentEditor, contentEditor.ZoneID, 0);

                                web.Update();
                            }
                        }
                    }
                }
                finally
                {
                    web.AllowUnsafeUpdates = false;
                }
            }
        }
    });
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top