Question

Salvete! I have a Content Editor Web part into which I want to load a simple bit of html (just an input box and a button or two). The file is at /_layouts/myfolder/myfile.html

When I use the "Test Link" option, the file displays fine. But when I "apply" the web part, I get this message in place of the web part: "Cannot retrieve the URL specified in the Content Link property. For more assistance, contact your site administrator."

Now, I am using an admin account - a domain admin account, in fact, so it can't be a permission problem.

I also tried it with a simple text file, but still no solution.

I also tried using an absolute address, such as "http://my.portal.org/_layouts/myfolder/myfile.html", but that didn't do anything either.

How is it that the simple html file can be displayed via "test link", but not as the web part?

I don't want to use a page-viewer, becuase I don't want the html to be in an iframe. I know I can put the html directly into the CEWP, but I want to reuse the html in several places and simply maintain one instance of the code.

Was it helpful?

Solution

For testing purposes, try putting your html file in a document library in your portal and reference it in the CEWP from there. Eg:

http://my.portal.org/Shared Documents/myfile.html

If this works, then I am guessing it is an authentication issue. Try replicating the issue in Firefox. If it is indeed an authentication issue, you will be prompted for credentials.

UPDATE:

After some digging around I found out that you can neither access content from the layouts folder nor from outside the site collection in the ContentLink property. This is a security feature implemented by Microsoft to avoid cross site scripting.

The only way to allow this is to enable Anonymous Access on the site collection. (in case of _layouts folder)

Or if you are referencing content from another site collection, you will have to enable anonymous access on it:

Enable Anonymous Access in SharePoint 2010

(Tested both options on my SP Environment)

The reason why it is working in the PageViewer Webpart is because:

From MSDN:

If the ContentLink URL points outside of the Windows SharePoint Services Web site to a site that requires authentication, then that site must be isolated. For this situation it is recommended that you use the PageViewerWebPart instead of the ContentEditorWebPart. The PageViewerWebPart renders content within an IFrame. With IFrames, security prompting occurs on the client, enabling the target user to specify a user name and password.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.contenteditorwebpart.contentlink.aspx

Another option is to use the Content Link Webpart (available on Codeplex) which is designed as a workaround for this same issue:

Content Link Web Part for SharePoint

OTHER TIPS

I was playing around with this recently on my dev box trying to setup a CEWP using javascript stored in a central document library. I like the idea of having the code for the widgets in one place which is already versioned and backed up. The fix that finally resolved this for me was setting up the alternate access mappings. Once I setup the AAM for the localhost the issue was cleared.

You cannot link using the content link across sites. I know this first hand. There are, however, workarounds.

I use this in the content editor web part "Content" section and am able to make cross-site references now.

<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
<![CDATA[​
<script src="jquery.js" type="text/javascript" langauge="javascript"></script
<script type="text/javascript">
    //enter javascript code here        
</script>
ENTER HTML HERE
]]></Content>

Recently got this message in SharePoint 2013 Online when referencing a HTML file in the Style Library. However, the issue was simply that the file was checked out.

Simply locate your file in Style Library, Mouse Hover and check the hyperlink location...

Something like '/sites/sitename/Style Library/FolderName/Filename.txt'

Just use this in Content Link Property and you are all set!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top