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

Import HTML file issue

3 Answers 151 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 15 Apr 2011, 04:32 PM
Hi,

i have a issue converting a docx file into a HTML file and then displayig the HTML in the RichTexBox control.
I am trying to upload a docx file with a table in it, by convertig the byte array into a RadDocument with the DocxFromatProvider.
This works great. Then i export the RadDocument into a HMTL string with the HtmlFormatProvider. This also works.
Then i try to create a new RadDocument with the generated HTML string and the HtmlFormatProvider. But it throws me a InvalidCastException. Here is my code:

                    data = dlg.File.OpenRead();
                    RadDocument tmpDoc = new DocxFormatProvider().Import(data);
                    
                    html = new HtmlFormatProvider().Export(tmpDoc);
                    Document = new HtmlFormatProvider().Import(html);

The last line causes the exception. The HTML in the string is valid html.
It seems that a docx containing a table can be converted in valid HTML, but it cannot been imported as RadDocument.
When i try to upload the generated html in your silverlight demo RichTextBox it says "The file cannot be opened".

Is there any solution for this issue?
Thanks a lot!


Greetings
Daniel

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 18 Apr 2011, 08:20 AM
Hello Daniel,

Basically, the document has two states depending on if it has been measured or not. Some operations expect that the document has been measured, while others can only be performed on not measured documents. Export of document requires that the document has been measured in advance and documents are not measured on import.
If you decide to export the document without showing it in the editor first, you would have to manually invoke the following method:

private void MeasureAndArrangeInDefaultSize(RadDocument document)
{
    document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
    document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
}

Note that this is not needed when you assign an imported document to a RadRichTextBox's Document property and show it on screen, as it will get measured by the Silverlight framework and everything will work OK.

Regards,
Iva
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
Daniel
Top achievements
Rank 1
answered on 21 Apr 2011, 02:21 PM
Hello,

unfortunately this does not solve the issue.
I included and invoked your method in my code, but the issue is the same. I still get the InvalidCastException.
You can recreate this scenario, when you try to upload a docx with a table in it, and then try to convert it into a HTML RadDocument.

My code looks like this:
        private void OnOpenDocumentCommand(object parameter)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Multiselect = false;
            dlg.Filter = "DOCX Files (.docx)|*.docx";
 
            if (dlg.ShowDialog() == true)
            {
                Stream data = dlg.File.OpenRead();
                RadDocument tmpDoc = new DocxFormatProvider().Import(data); 
 
                MeasureAndArrangeInDefaultSize(tmpDoc);
 
                string html = new HtmlFormatProvider().Export(tmpDoc);
                //The following line throws a InvalidCastException:
                RadDocument tmp2 = new HtmlFormatProvider().Import(html);
            }
        }
        private void MeasureAndArrangeInDefaultSize(RadDocument document)
        {
            document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
            document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
        }
0
Iva Toteva
Telerik team
answered on 21 Apr 2011, 03:58 PM
Hello Daniel,

We are not able to reproduce the issue on our end. Could you please open a support ticket of type "General Feedback" and send over a sample document that causes the exception?
Thank you for the involvement.

Kind regards,
Iva
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
Tags
RichTextBox
Asked by
Daniel
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or