Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Essentially what I want is to pre-load the existing content editor with some text may be from a configuration(by adminstrator) or from the list. So I am creating a custom wp that will act like a wrapper to the existing content editor and add some text to it. But this makes the CEWP uneditable to the user. Please suggest. I am using SharePoint 2010 foundation.

share|improve this question
add comment

2 Answers

Here's my working code for SP 2010 for adding text to the existing CEWP. I think it must be identical to the example mentioned above:

SPListItem pageItem;// Need to get page SPListItem
SPLimitedWebPartManager manager = SPContext.Current.Web.GetLimitedWebPartManager(pageItem.Url, PersonalizationScope.Shared);
            ContentEditorWebPart contentEditor = manager.WebParts.OfType<ContentEditorWebPart>().Single(); // You can choose a specific CEWP instance by any conditions if you like
            XmlDocument xDoc = new XmlDocument();
            var contentRoot = xDoc.CreateElement("ContentRoot");
            string content = "abcde!";
            contentRoot.InnerText = editor.Content;
            contentEditor.Content = contentRoot;
            manager.SaveChanges(contentEditor);
share|improve this answer
add comment

Wrapping the webpart with custom code shouldn't be needed; should be able to do what you want by updating the contents. The following article should get you moving in the right direction.

Programmatically Updating a SharePoint Content Editor Web Part -- note this is for SharePoint 2007, but as you didn't mention what version you are using...

share|improve this answer
    
I am using SharePoint 2010 foundation. –  Hna0002 Nov 7 '11 at 19:18
    
It is a great solution but what if I had more than one content editor on the page? I am looking more towards setting (preloading) text to a specific CEWP on the page and still keep it editable for the user. –  Hna0002 Nov 7 '11 at 19:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.