This is a migrated thread and some comments may be shown as answers.

Image or Element paths question

4 Answers 46 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Reid
Top achievements
Rank 2
Reid asked on 27 Apr 2011, 05:11 PM
When the Content property of the RadEditor is read during development it uses the url as localhost.  At runtime when the value is set in production it will of course need to to use the domain name. 

Anyone have an example of handling this efficiently?  I can of course use an HTMLHelper to parse the value and do a search and replace, just curious if there are any other putfals in this topic.

Thanks,
Reid

4 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 02 May 2011, 12:20 PM
Hello Reid,

By default the Image and Link Managers of RadEditor insert images and links with relative paths:

<img alt="" src="/Images/myImage.gif" />
<a href="/Documents/myDocument.docx">myDocument.docx</a>

So if the Images and Documents folders are configured in IIS as virtual folders pointing to the root of the web application then they will be visible in the public and in the development sites.

Of course, if you have paths with absolute URL then you can use String.Replace on the server to strip the domain name from the url/src paths.

All the best,
Rumen
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Reid
Top achievements
Rank 2
answered on 02 May 2011, 02:45 PM
This morning I replayed the issue and the "localhost" was not inserted.  At some point it was, maybe a remanant of a cut and paste.

This is resolved, local paths are being rendered.

Thanks!

Reid
0
Rumen
Telerik team
answered on 02 May 2011, 03:07 PM
Hello Reid,

If you cut and paste a link then the browser could create an absolute path. In this case try the solution provided at the end of the description of this live demo: OnClientPasteHtml, e.g.

The OnClientPasteHtml event is also fired when the Paste (Ctrl+V) command is executed. It is useful in scenarios when the pasted content should be modified and inserted in the content area.

For example when copying and pasting a link or an image with a relative path in Internet Explorer, the browser automatically converts the path to absolute. The code below demonstrates how to attach to the OnClientPasteHtml event and strip the desired url path using the StripPathFilter content filter. The StripPathsFilter() method receives as a parameter an array of strings (devided by a white space) that will be stripped from the absolute path.

<script type="text/javascript">
function OnClientPasteHtml(sender, args)
{
    var commandName = args.get_commandName();
    var value = args.get_value();
    
    if (commandName == "Paste")
    {
       // The StripPathsFilter() method receives as a parameter an array of strings (devided by a white space) that will be stripped from the absolute links.
        var domainName = "http://" + window.location.host; //returns the hostname and port number of the current URL
        var filter = new Telerik.Web.UI.Editor.StripPathsFilter([domainName]); //strip the domain name from the absolute path
                    
        var contentElement = document.createElement("SPAN");
        contentElement.innerHTML = value;
        var newElement = filter.getHtmlContent(contentElement);
        alert(newElement.outerHTML);
        args.set_value(newElement.outerHTML);  //set the modified pasted content in the editor
    }
}
</script>

Please, note that the OnClientPasteHtml event fires the Paste command only when the StripFormattingOnPaste property is not set to "NoneSupressCleanMessage". In this case the editor does not process the pasted content and pastes it without modifications.



Best wishes,
Rumen
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Reid
Top achievements
Rank 2
answered on 02 May 2011, 03:19 PM
Fantastic support. I will implement this.

Thanks again,
Reid
Tags
Editor
Asked by
Reid
Top achievements
Rank 2
Answers by
Rumen
Telerik team
Reid
Top achievements
Rank 2
Share this question
or