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

Is it at all possible to make changes to or add a content editor to a page using only the Client Object Model API? There does not appear to be any reference to a ContentEditorWebPart dll.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can't use the DLL as usual, you need to provide a Microsoft.SharePoint.Client.WebParts.WebPart, you can get this from WebPartDefinition which you again can get from LimitedWebPartManager.
Then you provide the correct definition, you can get this from exporting the Web Part.
You basically need <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly> and <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>.

Example:

var ctx = new ClientContext("http://localhost");
var page = ctx.Web.GetFileByServerRelativeUrl("/default.aspx");
var wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
var webPartDefinition = wpm.ImportWebPart(@"
  <?xml version='1.0' encoding='utf-8'?>
  <WebPart xmlns='http://schemas.microsoft.com/WebPart/v2'>
    <Title>Hello, Robert</Title>
    <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
    <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
    <Content><![CDATA[<strong>The Wheel weaves as the Wheel wills</strong>]]></Content>
  </WebPart>");
wpm.AddWebPart(webPartDefinition.WebPart, "Main", 0);
ctx.ExecuteQuery();
share|improve this answer

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.