0

Is it possible to use JavaScript to add a CEWP to a [New/Edit/Disp]Form.aspx? The CEWP would point to an HTML file that is in a document library.

I've got a normal SP list in SP 2010 that has a NewForm.asxp, EditForm.asxp, and DispForm.asxp. I know how to add a CEWP to them manually by going to edit mode and then adding the WebPart.

I want to accomplish that problematically with JavaScript. So the JavaScript would add a CEWP to the pages and point the CEWP content to an HTML file.

2
  • To clarify, you want a CEWP added to forms. This CEWP will load some library. Or do I have it backwards? Will the library be static or relative to the related list? Or if on 2013 are you attempting dynamic content?
    – user13186
    Commented Nov 5, 2015 at 1:57
  • @user13186: Yes, that sounds right. I added more details... Commented Nov 5, 2015 at 2:31

1 Answer 1

1

A similar question has been answered here. Is it possible to programmatically add a web part to a page in a sharepoint hosted app (JS)

You can specify your HTML file for the web part by adding a ContentLink node to the xml definition like this:

<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">path to your HTMl file.txt</ContentLink>
3
  • That was for 2013 and I wasn't sure if it would work with 2010? Commented Nov 5, 2015 at 12:56
  • CSOM was released with SP2010 so the code should work with 2010. Make sure that the SP.js is loaded on the page. Also there will be two changes in the web part xml definition 1. change the assembly to <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly> and 2. remove 15 from the <PartImageLarge> tag.
    – HarryB
    Commented Nov 5, 2015 at 13:06
  • Awesome! Let me test this and if it works I'll mark as answer. Thanks @HarryB! Commented Nov 5, 2015 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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