Ajout à la description WebPartPage lors de la création la page
-
15-10-2019 - |
Question
Je suivais cette méthode (http://msdn.microsoft.com/en-us/library/ms450826.aspx) pour ajouter un webpartpage (samplewpp.aspx) et il fonctionne. Cependant, je dois ajouter une description de la ligne ainsi. Comment?
Pas de solution correcte
Autres conseils
Vous devez ajouter un composant Web Content Editor (de CEWP) à la page et ajoutez votre description à ce sujet. Le CEWP vous permet de mettre du texte / html sur une page.
Pour ce faire programatically puis suivez quelque chose comme ce code par 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;
}
}
}
});
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow