Insert image in content yield corrupted source

Topics: General
Feb 3, 2011 at 7:45 PM

Hey! Anyone else than me who have problems inserting images i C1 Beta 4 (2.1.4047.4307)

When inserting an image in content i get the following tag in my source where the problem lies in the prepended ~

<img src="~/Renderers/ShowMedia.ashx?id=77ed6db5-edd3-4f43-beae-0ffbb95b4bda" />

If i do exactly the same in an older installation, SP1 (2.0.3947.24461) i get the following which is more correct

<img src="/Renderers/ShowMedia.ashx?id=b21a1b36-6ef5-4935-bf7f-a2d4f1554fd2" />

So what happened, why is the tilde prepended to the final html sent to the clients browser, when it will result in a image not found?

Feb 4, 2011 at 10:44 AM

I tried grabbing the latest sources from CodePlex and did tests inserting images from both dev and operational mode - no problems.

We did a number of check-ins the recent days with changes to "insert images" so I guess you can grab the latest beta sources and you should be fine.

Feb 4, 2011 at 12:14 PM

I had some problems getting the source to 5308 so it should be 5257 it is running on. I'll try again to force my TeamCity to get and build the newest source. Long live the internet in Greenland (NOT).

Feb 4, 2011 at 1:40 PM

Okay, now i got the source for 5308 and the problem seems to have disappeared. Looking through the changesets i cant seem to figure out though what change should have made this problem appear and disappear again. Anyway, we're all happy, the sun is shining and its friday! :)

Feb 4, 2011 at 3:17 PM

okay... i was too fast here! i copied all the files from /Website to my folder on the webserver, emptied the browsers cache and all that, and the problem reappeared.

Steps to reproduce

  • Open a page for content editing
  • Put the cursor somewhere on the page
  • Choose Insert > Image
  • Choose an image from the selector and press ok
  • The value of the "Source" textbox is correct in the Insert Image dialog (/Renderers/ShowMedia.ashx?id=7af55fc6-a4e5-431e-a85b-11f55214860d)
  • Press ok
  • The image is correctly shown in the content editor
  • Press the "Source" button
  • The src of the image-tag is now ~/Renderers/ShowMedia.ashx?id=7af55fc6-a4e5-431e-a85b-11f55214860d


Feb 4, 2011 at 3:22 PM

By the way, Image Properties seems to be throwing an javascript error: "ReferenceError: href is not defined"

Feb 4, 2011 at 3:25 PM

That behavior is by design - the persisted xhtml (which is what you also see in the source view) will use ~ to ensure that your website will work as expected in both a root and a sub folder. Without the ~ links and images will break if moving to/from/between folders.

Inside the WYSIWYG editor we need to use the path which is valid at the moment of editing, so the image can be shown.

Feb 4, 2011 at 3:27 PM

But where is the code that will scan all the html and replace ~ at runtime when the page is rendered?

Feb 4, 2011 at 3:30 PM

> But where is the code that will scan all the html and replace ~ at runtime when the page is rendered?

You can find it in the "PageRenderer" class, "ResolveRelativePaths".

> By the way, Image Properties seems to be throwing an javascript error: "ReferenceError: href is not defined"

Can you give a repro for that one?

Feb 4, 2011 at 3:39 PM

aw please, give me some slack here! you made the function private, its not easy to extend things when there are so much internal stuff going on!

Feb 4, 2011 at 3:57 PM

updated my page.aspx.cs code so it now calls the private static method ResolveRelativePaths and thing works as it should...

I'm usually pretty careful reading through all the code when you do check-ins to make sure to catch something that will affect my extensions, but when we're talking about private or internal methods they usually go under my radar since its... well, internal and private.


Feb 4, 2011 at 4:00 PM

about the ReferenceError it seems to be reproduciblejust by clicking on any insterted image in the content area and selecting the "Image Properties" button 

Feb 4, 2011 at 6:18 PM
Edited Feb 4, 2011 at 6:18 PM

If you don't want to make ResolveRelativePaths and NormalizeXhtmlDocument public, at least make sure that ExecuteEmbeddedFunctions calls them internally.