Export TO Markdown

4 posts, 0 answers
  1. andrew
    andrew avatar
    11 posts
    Member since:
    Sep 2008

    Posted 21 Jan 2014 Link to this post

    Can anyone show a code sample of how I can retrieve content from a RadEditor as markdown on the server (not on the client)?

    I have read this demo page and it says to use OnExportContent but I'm not sure how to do that. 
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 23 Jan 2014 Link to this post

    Hello Andrew,

    Here is a small sample that shows how you can get the markdown string and return the user to the current page without him/her getting the exported content:
    protected void RadEditor1_ExportContent(object sender, EditorExportingArgs e)
    {
        if(e.ExportType == ExportType.Markdown){
            doSomething(e.ExportOutput);//use the output generated from the editor, e.g., to create a file and save it on the server
            //note that the output is the markdown string, it is not a file yet
            Response.Redirect("default.aspx");//return to the current page
        }
    }
     
    protected void Button1_Click(object sender, EventArgs e){
        RadEditor1.ExportToMarkdown();
    }
     
    protected void doSomething(string content)
    {
     
    }
    <telerik:RadEditor ID="RadEditor1" runat="server" OnExportContent="RadEditor1_ExportContent">
    <Content>
    <strong>some bold text</strong>
    <br />
    <em>some italic text</em>
    </Content>
    </telerik:RadEditor>
    <asp:Button ID="Button1" Text="export to MD" OnClick="Button1_Click" runat="server" />



    Regards,
    Marin Bratanov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. andrew
    andrew avatar
    11 posts
    Member since:
    Sep 2008

    Posted 23 Jan 2014 Link to this post

    Thanks Marin.

    I have tried to use your code so it outputs markdown to a Textbox that's in my ASPX page.

    For example:
     
    protected void RadEditor1_ExportContent(object sender, EditorExportingArgs e)
    {
       if (e.ExportType == ExportType.Markdown)
       {
          tbMarkdown.Text = e.ExportOutput;
        }
    }

    Instead of seeing a rendering of my ASPX page along with tbMarkdown, the response was just the exported markdown. How can I render my aspx page with the exported markdown?

    Also, would you know why Markdown has to be retrieved through an event handler? Why can't markdown be retrieved using a standard property/method (eg: calling RadEditor1.GetMarkdown() to get Markdown).

    Thanks! 

  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 24 Jan 2014 Link to this post

    Hello Andrew,

    The export logic is designed to send the new content to the user, i.e., change the response. This is why my sample had a Redirect() call. Thus, you cannot change controls on the page at this point. Redirecting back to the current page lets you consume the exported content without sending it to the user. If you want to use it on the page - store it in a Session or Cache variable (or database, or file), and when the page loads - check for this object and populate the control.

    On such a simple property - this was not the intention of the export functionality. If you like you can log this idea in our feeback portal and if it gets traction in the community we will consider its implementation: http://feedback.telerik.com/project/108. You may also find interesting this blog post on plugging your own exporting libraries.


    Regards,
    Marin Bratanov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top