Search This Blog

Sunday, March 1, 2009

Adding a Content Editor web part programmatically

private void AddContentEditorWebPart(SPLimitedWebPartManager mgr, int zoneIndex)
ContentEditorWebPart cewp = new ContentEditorWebPart();
XmlDocument doc = new XmlDocument();
XmlElement ele = doc.CreateElement("One");
ele.InnerXml = "<![CDATA[<hr style=\"height:1px;color:#939393\"/>]]>";
cewp.Content = ele;
cewp.ChromeType = AspWebParts.PartChromeType.None;
mgr.AddWebPart(cewp, ZoneWebPart, zoneIndex);

In the above example, CEWP is used for adding a horizontal line.

A note of caution: Content Editor web part should not be used if you are using link to images or documents since the absolute references are not updated automatically when content is migrated from one environment to another.

No comments: