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

get RTF string or stream

9 Answers 351 Views
Editor
This is a migrated thread and some comments may be shown as answers.
lenuweit
Top achievements
Rank 1
lenuweit asked on 10 Jun 2010, 09:42 PM
Hello people,

I use for my Webapplication the RadEditor for wiriting notes. This notes are saved in a database.
Since it is formatted text, I need the RTF string. So far I execute ExportToRtf() and I use the onExportContent-Event. In my event handler I manage to get the rtf-string with:
 protected void OnExportContentEvent( object sender,EditorExportingArgs e ) {         
        string rtf = e.ExportOutput; 
        SaveNote( rtf ); 
        ... 
    } 

This works just fine, except one problem. A dialog pops up asking to save the RTF-File. Is there a way to suppress this dialog?

Thank you for your help.

9 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 14 Jun 2010, 03:42 PM
Hi Lenuweit,

You should set the OpenInNewWindow attribute to false, e.g.

<telerik:RadEditor ID="RadEditor1" runat="server" SkinID="DefaultSetOfTools">
            <ExportSettings OpenInNewWindow="true" FileName="RtfEditor">
                <Rtf PageHeader="RadEditor content" />
            </ExportSettings>
</telerik:RadEditor>


Kind regards,
Rumen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
lenuweit
Top achievements
Rank 1
answered on 15 Jun 2010, 11:01 PM
Hello Rumen,

thanks for your reply. But your suggestion doesn't work. I still get the popup window asking me if I want to download the rtf-file. Here is my code:

<telerik:RadEditor runat="server" ID="reMainEditor" Height="150" OnExportContent="OnExportContentEvent"
ToolsFile="~/controls/TabNotesToolsFile.xml" EditModes="Design" Width="100%" > 
                     <ExportSettings OpenInNewWindow="false" >                 
            </ExportSettings> 
        <Content>         
</Content>     
</telerik:RadEditor>   

And that's what's happening in my code behind file:

 protected void rtbSave_ButtonClick( object sender,RadToolBarEventArgs e ) { 
        switch( e.Item.Value ) { 
            case "Save":                             
                reMainEditor.ExportToRtf();                 
                break
            case "Cancel":                 
                break
        }         
    } 
 
 protected void OnExportContentEvent( object sender,EditorExportingArgs e ) {         
        string rtf = e.ExportOutput; 
        SaveNote( rtf ); 
        reMainEditor.Content = string.Empty; 
        LoadNotesEditors(); 
    } 

Can you please tell me what I am doing wrong?

Thank you.

0
Rumen
Telerik team
answered on 16 Jun 2010, 03:48 PM
Hello Lenuweit,

For your convenience I have attached a sample working project that demonstrates how to export to RTF without popping up a notification dialog.


Sincerely yours,
Rumen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andreas Ladis
Top achievements
Rank 1
answered on 09 Jul 2010, 09:57 AM
Hi,

I checked your demo it is quite good.

Is there a similar example for importing rtf documents to the editor.
I mean just set the filename on code-behind hit a button and the file get imported.

I checked in your online demos and i found nothing.

Thanks in advance.

Regards,
Eleni
0
Rumen
Telerik team
answered on 09 Jul 2010, 10:08 AM
Hi Eleni,

You can load a rtf file as a string using this code:

protected void Page_Load(object sender, EventArgs e)
{
        if (!Page.IsPostBack)
        {
            FileStream fileStream = new FileStream(Server.MapPath("RtfEditor.rtf"), FileMode.Open, FileAccess.Read);
            RadEditor1.LoadRtfContent(fileStream);
        }
}

A sample project working project which demonstrates the above functionality is attached here.

Best regards,
Rumen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
loowool
Top achievements
Rank 2
answered on 17 Jul 2010, 03:15 PM

Dear Telerik,
I downloaded both demo projects that you listed on this post. They both Work. Great.
But I tried to combine them both into 1, i.e. an Editor that reads an RTF file, edits it, and Saves output in the same RTF file. I faced some problems that I'd like your help with.

To replicate my situation, please follow these steps:

1) Download the first demo listed above: 199592_exporttortf-q12010sp2.zip
2) Open it in Visual Studio and Run it (it works, i.e. the editor content is: sample content 123
3) Open the Default.aspx.cs file and change the Page_Load Handler From:

protected void Page_Load(object sender, EventArgs e)
{
    url = String.Format("~/{0}.rtf", RadEditor1.ExportSettings.FileName);
    path = Server.MapPath(url);
}

To:

protected void Page_Load(object sender, EventArgs e)
{
    url = String.Format("~/{0}.rtf", RadEditor1.ExportSettings.FileName);
    path = Server.MapPath(url);
    if (File.Exists(path)) 
        using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) 
            RadEditor1.LoadRtfContent(fileStream);
}
This way, the file saved the first time will be loaded the second time if it exists.
4) Make sure you delete the RadEditorExport.rtf, then run it, don't change the editor content
5) Click on the Button below the editor to Export the Content to RTF
6) Since the Response is Redirected again to the same page, the Page Load will now Load the RTF file, but the editor Content is not: sample content 123 but samplecontent123
7) Now, Click on the same Button below the editor to Export the Content to RTF again, you obtain a crash saying:

Invalid XHTML. RadEditor content should be correct XHTML in order to export to RTF.
Parse error:
The 'p' start tag on line 673 position 12 does not match the end tag of 'body'. Line 673, position 218.
at line:
<body><p><span style="background-color:#FFFFFF;font-size:11pt;">sample</span><span style="background-color:#FFFFFF;font-size:11pt;">content</span><span style="background-color:#FFFFFF;font-size:11pt;">123</span></body>

...
Please help us solve the above 2 problems.
NB: I tried the online demo: https://demos.telerik.com/aspnet-ajax/editor/examples/rtfexport/defaultvb.aspx but it gives me a "Not Found" error when I press the Export RadEditor Content to RTF button and redirects me to the page: https://demos.telerik.com/ErrorPageResources/error.aspx?aspxerrorpath=/aspnet-ajax/editor/examples/rtfexport/defaultvb.aspx

Thanks again to your Great Support (as always)

Salah A. Malaeb
TeknoBuild
0
Dobromir
Telerik team
answered on 21 Jul 2010, 02:29 PM
Hi Salah,

I already answered your support ticket on the subject. For convenience I will paste my answer here as well.

RadEditor is using third party tool to provide RTFtoHTML conversion which has some problems and limitations. We do have planned an improvement to this tool, but I cannot give you firm estimate of when it will be available. Unfortunately, at present I cannot provide suitable workaround for this problem. Please excuse us for the inconvenience.

Regarding the Parse Error exception, the problem occurs, because the content, when loaded from the RTF file, is not XHTML compliant, and the exporting tool requires valid code to operate with. This problem is handled by RadEditor's built-in content filters, but when you are trying to execute the second Export, the Page_Load event is fired again, and the content is loaded once again. You can avoid this problem by adding !IsPostBack condition before loading the RTF content, e.g.:


protected void Page_Load(object sender, EventArgs e)
{
    url = String.Format("~/{0}.rtf", RadEditor1.ExportSettings.FileName);
    path = Server.MapPath(url);
    if (File.Exists(path) && !IsPostBack)
        using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
            RadEditor1.LoadRtfContent(fileStream);
}


Regards,
Dobromir
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Luca
Top achievements
Rank 1
answered on 15 Feb 2012, 05:20 PM
good evening,
I also like others I have a similar problem.
I am using the RadEditor to allow the user to enter notes, them after are then stored in my database.
notes are then loaded into a Telerik report by a richtextbox (I tried the htmltextbox and the result is much worse).

I used the features described above to obtain the rtf string, but got substantial management problems.
I attach a sample file with some images:

Step1.png -> what I save
Step2.png -> what is actually saved
Step3.png -> what is subsequently reloaded

is all three steps are substantially different.
is a feature that interests me particularly because it allows users to use the notes field of the report as if it were a page in Word.

Waiting for news.
good Day
0
Rumen
Telerik team
answered on 17 Feb 2012, 04:01 PM
Hello,

RadEditor uses two different free libraries to provide Import to RTF and Export to RTF features.

The first one used to provide RFT to HTML importation is available in this CodeProject's article: http://www.codeproject.com/KB/recipes/RtfConverter.aspx.
The library used for HTML to RTF exportation is available here http://www.codeproject.com/KB/HTML/XHTML2RTF.aspx.
Both libraries are written by different developers and they are not fully compatible with each other.

For your convenience I prepared a list of know limitations of the Import and Export features of both libraries:

RFT to HTML (Import)

bold
- supported..
italic - supported
underline - supported
foreground and background colors - supported
table elements - unsupported
images- unsupported
indentations - unsupported
superscript and subscript - unsupported

HTML to RTF (export)


bold - supported.
italic - supported
underline - unsupported
foreground and background colors - unsupported
table elements - partially supported - table borders are not exported
images- unsupported
indentations - supported
font family and size - unsupported
superscript and subscript - unsupported

The unsupported scenarios are hard for implementation and require time for implementations and testing. Our development is concentrated currently on producing valid XHTML content, new features and dialogs and the import and export problems are logged with medium priority in our ToDo list. That is why we could not provide firm estimate for when the unsupported features will be available.

Please note that good RTF import and export tools are very expensive. If you are currently unsatisfied with the offered by RadEditor RTF functionality, you could search in Internet for another free or paid RTF to HTML importation and HTML to RTF exportation tools and we will help you to integrate them with RadEditor.

Best regards,
Rumen
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Editor
Asked by
lenuweit
Top achievements
Rank 1
Answers by
Rumen
Telerik team
lenuweit
Top achievements
Rank 1
Andreas Ladis
Top achievements
Rank 1
loowool
Top achievements
Rank 2
Dobromir
Telerik team
Luca
Top achievements
Rank 1
Share this question
or