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

Export TO Markdown

3 Answers 61 Views
Editor
This is a migrated thread and some comments may be shown as answers.
andrew
Top achievements
Rank 1
andrew asked on 21 Jan 2014, 09:28 PM
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. 

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 23 Jan 2014, 11:42 AM
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.
0
andrew
Top achievements
Rank 1
answered on 23 Jan 2014, 03:11 PM
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! 

0
Marin Bratanov
Telerik team
answered on 24 Jan 2014, 03:59 PM
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.
Tags
Editor
Asked by
andrew
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
andrew
Top achievements
Rank 1
Share this question
or