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

upload strips html

3 Answers 86 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 07 Dec 2008, 03:03 PM
when i upload a file with <meta http-equiv="content-type" content="text/html; charset=utf-8" />

on it

the upload process removes the <meta http-equiv="content-type" content="text/html; charset=utf-8" />

please advise.

thanks.

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 10 Dec 2008, 11:34 AM
Hi Jeff,

How do you upload the file? Do you use one of the RadEditor FileBrowser dialogs?
Please, give us steps to reproduce and more information on what you do.

Our suggestion is to open a support ticket - send us a sample html file for us to upload and more information how you test that a tag is missing.

Please, note that if you insert the uploaded file through the template manager in the editor, the browser will automatically strip the html, head and body tags. The meta tag will be also stripped because it is not possible to place a meta tag in the body.

If this is your scenario, you can insert a full html page through the template manager by following the steps below:
  1. Place the EditorDialogs installation folder to the root of your web application
  2. Set the ExternalDialogsPath property to point to the EditorDialogs folder, e.g.

    <telerik:RadEditor ID="RadEditor1" ExternalDialogsPath="~/EditorDialogs"
    OnClientPasteHtml="OnClientPasteHtml"  runat="server">
        <Content>
        </Content>
      <TemplateManager ViewPaths="~/files" UploadPaths="~/files" />
    </telerik:RadEditor>
     
  3. Open the \EditorDialogs\TemplateManager.ascx dialog file and modify the getResult function:

        getResult : function()
        {
            if (this._currentItem && this._currentItem.type == Telerik.Web.UI.Widgets.FileItemType.File && this.isValidExtension())
            {
                //OLD
                //this._currentTemplateItem.contentWindow.getElementsByTagName("HTML")[0].innerHTML;

               
                //NEW
                var test = "<html>" + document.getElementsByTagName("IFRAME")[0].contentWindow.document.getElementsByTagName("HTML")[0].innerHTML + "</html>";
                return test;

            }
            return null;
        },
    ...
    This change will return full html content to the editor on the parent window.
     
  4. Since the browser itself will strip the <html>, <head> and <body> tags, we need to capture the supplied content from the Template manager and paste it in the editor with the set_html() method. We can do that by attaching to the OnClientPasteHtml event property of RadEditor, e.g.

    <telerik:RadEditor ID="RadEditor1" OnClientPasteHtml="OnClientPasteHtml" ExternalDialogsPath="~/EditorDialogs" runat="server">
        <Content>
        </Content>
      <TemplateManager ViewPaths="~/files" UploadPaths="~/files" />
    </telerik:RadEditor>
    <script type="text/javascript">
    function OnClientPasteHtml(editor, args)
    {
        var commandName = args.get_commandName(); //returns the command name
        var value = args.get_value(); //returns the content / value of the fired command

        if (commandName == "TemplateManager")
        {
            editor.set_html(value);
        }
    }
    </script>
You can download a sample project demonstrating the solution above from here.


Kind regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeff
Top achievements
Rank 1
answered on 11 Jan 2009, 12:26 AM
Rumen,

time finally permitted me to take another shot at this - the example you sent me sure does work at keeping the html in tact for an upload - however if you select an existing file it puts the content in twice - please help - thanks much - happy new year.

Jeff
0
Rumen
Telerik team
answered on 13 Jan 2009, 09:59 AM
Hi Jeff,

Please, excuse me for the omission.

To fix the double paste problem, you should cancel the paste command that is fired after the set_html method execution. You can do that by setting args.set_cancel(true); below the editor.set_html(value); line, e.g.

<telerik:RadEditor ID="RadEditor1" OnClientPasteHtml="OnClientPasteHtml" ExternalDialogsPath="~/EditorDialogs" runat="server">
    <Content>
    </Content>
  <TemplateManager ViewPaths="~/files" UploadPaths="~/files" />
</telerik:RadEditor>
<script type="text/javascript">
function OnClientPasteHtml(editor, args)
{
    var commandName = args.get_commandName();
    var value = args.get_value();

    if (commandName == "TemplateManager")
    {
        editor.set_html(value);
        args.set_cancel(true);
    }
}
</script>

All the best,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Jeff
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or