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

UpdateAllFields deprecated

10 Answers 77 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 20 May 2014, 06:16 PM
I have a custom set of fields in a document and am using UpdateAllFields() when I want to render a completed document. I notice from the documentation that this is deprecated. What should I be using instead?

Thanks,
John

10 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 21 May 2014, 08:48 AM
Hello John,

Indeed, several methods of RadDocument including UpdateAllFields() were recently marked as obsolete. Instead of them, you should use the respective method of RadRichTextBox or in case the document is not shown in UI at this point - RadDocumentEditor. This article explains in details the purpose and possible uses of RadDocumentEditor.

I hope this is helpful.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
John
Top achievements
Rank 1
answered on 21 May 2014, 10:50 AM
Thanks. I am generating my document using code only so the RadDocumentEditor is the way to go. I am running in a thread so was hoping to avoid the "The calling thread must be STA, because many UI components require this" error. Since it looks like the RadDocumentEditor is designed for code only operation can you suppress this in future releases? (I've got round the problem using information from here at the moment.)
Regards,
John
0
John
Top achievements
Rank 1
answered on 22 May 2014, 08:55 AM
I've now added a xaml powered spinner which displays when the document is rendering. Unfortunately, the spinner stops turning when I run the thread that attaches to the UI, which makes my request for RadDocumentEditor to not require the UI thread even more important. Will you be able to implement this or is this outside of your control. Is there another way to run UpdateAllFields()?
Thanks,
John
0
John
Top achievements
Rank 1
answered on 22 May 2014, 09:44 AM
ok, I think I've narrowed this down to the PdfFormatProvider, not the RadDocumentEditor, so I've wrapped the pdf.Export() function in a   System.Windows.Application.Current.Dispatcher.Invoke call and that reduces the stoppage to a minimum.
Regards,
John
0
Boby
Telerik team
answered on 26 May 2014, 07:39 AM
Hi John,
You are right, with the current implementation PDF export of RadRichTextBox's content can be performed only in the UI thread, as it uses UIElements which are then passed to the WPF printing system.

Otherwise RadDocument can be created and manipulated using the RadDocumentEditor in a background thread.

Don't hesitate to contact us if you have other questions.


Regards,
Boby
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
C
Top achievements
Rank 1
answered on 02 Jul 2014, 11:10 PM
John,

Please post example code of how to do this using RadDocumentEditor.  I'm facing the same thing of creating a word document in code with no UI and a TOC field which needs to be updated before the document is written to a .docx file.
0
John
Top achievements
Rank 1
answered on 04 Jul 2014, 08:28 AM
C,

Here is the code I use. I am using a xaml formatted document as the source, mail merging the fields and then converting it to pdf.

The form for me is stored in a database, hence line 4 loading the layout from the FormDefinitionRepository.

I also found that the pdf formatter can't handle errors in the merge/export particularly well so I found that updating it in xaml first then converting it to pdf did the trick for me. I know this isn't efficient but at least it doesn't kill the application.

XamlFormatProvider provider = new XamlFormatProvider();
 
// load the document
RadDocumentEditor tb = new RadDocumentEditor(provider.Import(uow.FormDefinitionRepository.Single(w => w.Id == Request.FormId).Layout));
tb.Document.MailMergeDataSource.ItemsSource = currEntity.EntityValues;

// perform the merge
tb.UpdateAllFields();
 
// render it to xaml and back again
// the Xaml exporter can handle errors in the merge whereas the pdf exporter can't
// if the pdf exporter crashes it takes down the whole application so its safer to let the xaml exporter handle the errors
string tempDoc = provider.Export(tb.Document);
RadDocumentEditor mergedDoc = new RadDocumentEditor(provider.Import(tempDoc));
 
// now set up the pdf export
PdfFormatProvider pdf = new PdfFormatProvider();
 
byte[] export = null;
 
// The pdf export needs to be run on the UI thread otherwise it crashes with a "The calling thread must be STA,
// because many UI components require this"
System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new System.Action(() =>
{
    try
    {
        export = pdf.Export(mergedDoc.Document);
        success = true;
    }
    catch (Exception e)
    {
        Log.Info("Pdf Conversion failed: FormId:{0} EntityId:{1} Exception:{2}", Request.FormId, Request.EntityId, e.Message);
        success = false;
    }
}));

Hope this helps.
John
0
Anand
Top achievements
Rank 1
answered on 31 Jul 2014, 10:26 AM
Hi Boby,

I have very similar issue to the one above. Have a big document of say 150 fields and I am trying to update all the fields in the document, and it takes at-least 2.5 mins to update it, since it is UI operation I have to do it on UI thread, which makes the UI to hang. 
I tried SuspendUpdateLayout before calling UpdateAllFields, but no improvement. 

Would appreciate, if you suggest me a solution to do this please. Below is the code snippet:

var editor = new RadDocumentEditor(_richTextBox.Document)            {                               RespectDocumentProtection = false             };
editor.UpdateAllFields(FieldDisplayMode.Result);
and I tried calling straight on _richTextBox as well
_richTextBox.UpdateAllFields(FieldDisplayMode.Result);

Thanks 
Anand



_richTextBox.UpdateAllFields(FieldDisplayMode.Result);






0
Boby
Telerik team
answered on 05 Aug 2014, 06:56 AM
Hello Anand,
Which is the version you are using? We have recently optimized the performance of the UpdateAllFields method and it currently updates document with 150 simple fields for about 2 seconds.

I would also suggest you to open a separate support ticket and send us the problematic document (exported in XAML format) there - this would be the easiest way to investigate the problem.

Regards,
Boby
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Anand
Top achievements
Rank 1
answered on 13 Aug 2014, 08:23 AM
Hi Boby,

Thanks for your reply. As you said, I read Telerik have improved the UpdateField performance. May be I will use the latest version and check how it works.

Cheers
Tags
RichTextBox
Asked by
John
Top achievements
Rank 1
Answers by
Petya
Telerik team
John
Top achievements
Rank 1
Boby
Telerik team
C
Top achievements
Rank 1
Anand
Top achievements
Rank 1
Share this question
or