Frage

Ich folge diesem (http://msdn.microsoft.com/en-us/library/ms450826.aspx) Methode zum Hinzufügen einer WebPartPage (samplewpp.aspx) und es funktioniert. Ich muss jedoch auch eine Zeilenbeschreibung hinzufügen. Wie?

Keine korrekte Lösung

Andere Tipps

Sie müssen der Seite einen Content Editor Web Part (CEWP) hinzufügen und dann Ihre Beschreibung hinzufügen. Mit dem CEWP können Sie Text/HTML auf eine Seite setzen.

Um dies programmatisch zu tun und dann folgen So etwas wie dieser Code von 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;
                }
            }
        }
    });
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top