【问题标题】:Adding description to WebPartPage when creating the page创建页面时向 WebPartPage 添加描述
【发布时间】:2011-06-03 15:22:04
【问题描述】:

我正在按照这个 (http://msdn.microsoft.com/en-us/library/ms450826.aspx) 方法添加 webpartpage (samplewpp.aspx) 并且它可以工作。但是,我还需要添加一行描述。怎么样?

【问题讨论】:

  • 描述应该在哪里?在页面上?在页面的元数据中?
  • 在加载页面(samplewpp.aspx)的页面上

标签: sharepoint sharepoint-2007 webpartpage


【解决方案1】:

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

要以编程方式执行此操作,请关注 something like this code by 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;
                }
            }
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多