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

Load multiple documents to a radDocument[] array

7 Answers 113 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Sandhya
Top achievements
Rank 1
Sandhya asked on 25 Jul 2016, 05:16 AM

Hi,

I am trying to load documents to a radDocument[] array. When executing below code i  get "exception has been thrown by the target of an invocation c#" error.  Kindly Help.

Here is my code:

RadDocument[] Rd_Ary = new RadDocument[2];
            
Rd_Ary[0]=ImportHtml(Convert.ToString("<P>String1</P>"));
Rd_Ary[1] = ImportHtml(Convert.ToString("<P>String2</P>"));

Alternative code:

 Rd_Ary.SetValue(ImportHtml(Convert.ToString("<P>String1</P>")), 0);
 Rd_Ary.SetValue(ImportHtml(Convert.ToString("<P>String2</P>")), 1);

7 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Jul 2016, 11:16 AM
Hi Sandhya,
 
Thank you for writing.

I have tested this with the following code and there is no exception on my side: 
void button_Click(object sender, EventArgs e)
{
    RadDocument[] Rd_Ary = new RadDocument[2];
 
    HtmlFormatProvider provider = new HtmlFormatProvider();
    
    Rd_Ary[0] = provider.Import(Convert.ToString("<P>String1</P>"));
    Rd_Ary[1] = provider.Import(Convert.ToString("<P>String2</P>"));
}

What is the code inside your ImportHtml method? Maybe something is different. 

I am looking forward to your reply.

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Sandhya
Top achievements
Rank 1
answered on 25 Jul 2016, 11:25 AM
public RadDocument ImportHtml(string content)
        {
            try
            {

                XamlFormatProvider provider = new XamlFormatProvider();
                return provider.Import(content);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
0
Dimitar
Telerik team
answered on 25 Jul 2016, 01:06 PM
Hello Sandhya,

Such input cannot be imported with the XamlFormatProvider. You can use the HtmlFormatProvider instead, or the RichTextEditor to save the  documents first. 

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Sandhya
Top achievements
Rank 1
answered on 25 Jul 2016, 01:22 PM

Hi,

Thanks for your reply.

I used HtmlFormatProvider and my output was this Telerik.WinForms.Documents.Model.RadDocument

0
Dimitar
Telerik team
answered on 26 Jul 2016, 07:26 AM
Hello Sandhya,

This is the expected result. Then you can show the document in RadRichTextEditor like this:
void button_Click(object sender, EventArgs e)
{
    RadDocument[] Rd_Ary = new RadDocument[2];
 
    var provider = new HtmlFormatProvider();
    string s = provider.Export(radRichTextEditor1.Document);
 
    Rd_Ary[0] = provider.Import(Convert.ToString("<P>String1</P>"));
    Rd_Ary[1] = provider.Import(Convert.ToString("<P>String2</P>"));
 
    radRichTextEditor1.Document = Rd_Ary[1];
}

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Sandhya
Top achievements
Rank 1
answered on 27 Jul 2016, 10:57 AM

Hi,

Thanks for your reply.My problem is solved.

I have one more doubt.

I want to set header and footer programmatically in a richtextEditor when loading a template.How can i achieve it.

0
Dimitar
Telerik team
answered on 27 Jul 2016, 12:40 PM
Hello Sandhya,

The following section shows how you can create a header and add it to a document: Headers and Footers.
 
I hope this will be useful. 

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
RichTextEditor
Asked by
Sandhya
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Sandhya
Top achievements
Rank 1
Share this question
or