Friday, June 15, 2012

Insert Picture From SharePoint is disabled in CEWP

Recently I came across a scenario in which the user was using content editor web part (CEWP) and using the Rich Text Editor ribbon of SharePoint 2010 to format the content. The user noted that "Insert Picture From SharePoint" option is disabled on a page.



I started investigating and came across MSDN Forum where it is mentioned that activating a publishing feature will resolve the issue. The site must be in publishing context. In our case, the site has the publishing feature activated.

We tried creating various kind of pages (Wiki Page, Web Part Page and Publishing Page). The option was enabled for every kind of page on the same site.

The option was disabled for only one page i.e. default.aspx. The page resides at the site root. I created a web part page in "Site Pages" and verified the option is enabled for the page. I opened the site in SharePoint Designer 2010. I moved the page to the site root. Again, I browsed for the page in edit mode and verified the option, it was disabled.

The page at site root does not belong to any library and has no associated content type for it. The page has few content management features disabled such as "Versioning", "Edit Properties". This is because the page was not child of any library (an orphan page or the parent is site).

Publishing feature has a strong bond with content management features. As the page do not have content management features available, it was not able to take advantage of the publishing context also. That's the reason, it was showing "Insert Picture From SharePoint" in disabled state.

This is not only this option, it also disables capabilities to cut, copy, paste in the Rich Text Editor.

Wednesday, June 13, 2012

Content Editor Web Part duplicating content

Today I received a request mentioning that Content Editor Web Part is duplicating the content. The user was adding clock object prepared in Adobe Flash. This clock was being duplicated whenever the user is editing the web part.

I checked the content editor web part. It has got too many "<embed>" tag. The tags were being duplicated. The clock was being rendered using some JavaScript method. We inspected the method. The method was using "document.write" to add the "<embed>" tag.

Content editor web part renders its HTML/JavaScript content on its canvas. So document.write was adding "<embed>" tag on every "Save" for the web part. So every edit action for the web part was adding "<embed>" tag causing duplicate clocks (content).

We resolved the issue by creating separate content file for Content Editor Web Part. The content file is linked to the Content Editor Web part. As the "document.write" is moved to separate file, for every request the file is read and parsed for render. "document.write" do not append content in the file. So it has no duplication of content.

Always use separate content file whenever we have a content which includes "document.write" in JavaScript.

More Reference(s):