Output full URL from document manager

8 posts, 0 answers
  1. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 14 Jan 2009 Link to this post

    We are using the Editor and allowing users to open the document manager and select an item and click insert. When they click Insert it will insert a link with the document name as the hyperlink text. Is there a way to make it output the full URL to the document instead of just the name of the document?

    Sometimes the text that is entered into the editor is being emailed to people as plain text and they need the full URL to get the document.
  2. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 19 Jan 2009 Link to this post

    Hi Adam,

    In order to insert links with full / absolute urls via the document manager, you should enable the MakeUrlsAbsolute content filter of RadEditor. You can do this by setting the following method in the codebehind:

    RadEditor1.EnableFilter(EditorFilters.MakeUrlsAbsolute);

    You can see the following example for more information: Built-in Content Filters.

    Best regards,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 19 Jan 2009 Link to this post

    The problem is not that the links are not absolute, it's that the text the Document Manager places in the editor is only the file name. For example, if I were to go in link to a file at http://www.test.com/test.doc and select it and click Insert, it would only put "test.doc" into the text window. What I want to appears as the link is the URL to the document....http://www.test.com/test.doc.

    Thanks,
    Adam
  5. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 19 Jan 2009 Link to this post

    Hi Adam,

    Thank you for the explanation of your scenario.

    You can achieve it using the OnClientPasteHtml event and modifying the link output from the Document manager. For your convenience I have wrote the code solution below:

    <script type="text/javascript"
    function OnClientPasteHtml(editor, args) 
        var commandName = args.get_commandName(); 
        var value = args.get_value(); 
     
        if (commandName == "DocumentManager"
        { 
            //See if an img has an alt tag set 
            var div = document.createElement("DIV"); 
     
            //Do not use div.innerHTML as in IE this would cause the image's src or the link's href to be converted to absolute path. 
            //This is a severe IE quirk. 
            Telerik.Web.UI.Editor.Utils.setElementInnerHtml(div,value); 
     
            //Now check if there is alt attribute 
            var link = div.firstChild; 
            link.innerHTML = link.href; 
             
             
            //Set new content to be pasted into the editor 
            args.set_value(div.innerHTML); 
        } 
    </script> 
    <telerik:RadEditor ID="RadEditor1" DocumentManager-ViewPaths="~/" OnClientPasteHtml="OnClientPasteHtml" runat="server"></telerik:RadEditor> 



    Kind regards,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 19 Jan 2009 Link to this post

    That pretty much works. However, it is only giving the relative path and not the full path. We have the EditorFilters.MakeUrlsAbsolute filter enabled, but it still returns relative links.

    Thanks,
    Adam
  7. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 19 Jan 2009 Link to this post

    Nevermind, I found something that works.

    link.innerHTML = window.location.protocol + '//' + window.location.host + link.href; 

  8. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 19 Jan 2009 Link to this post

    Hello Adam,

    Please, try the following solution:

    <script type="text/javascript">  
    function OnClientPasteHtml(editor, args)  
    {  
        var commandName = args.get_commandName();  
        var value = args.get_value();  
      
        if (commandName == "DocumentManager")  
        {  
            var div = document.createElement("DIV");  
            var link = document.createElement("A");  
           
            div.innerHTML = value
            link.innerHTML = div.firstChild.href;  
            link.href = div.firstChild.href; 
              
            //Set new content to be pasted into the editor  
            args.set_value("<href='" + link.href + "'>" + link.innerHTML + "</a>");  
        }  
    }  
    </script>  
    <telerik:RadEditor ID="RadEditor1" DocumentManager-ViewPaths="~/" OnClientPasteHtml="OnClientPasteHtml" runat="server"></telerik:RadEditor>  

    It worked as expected on my side and the link is inserted with absolute href and text.

    Best wishes,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 19 Jan 2009 Link to this post

    That works as well. Thank you.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017