I want to use a then close a RadFlowDocument.
My current process (will post code):
Open existing RadFlowDocument (word document).
Use RadFlowDocumentEditor to ReplaceText
Save the RadFlowDocument (now edited) as a new RadFlowDocument. (now it is open on my machine).
Serialize the saved document to send it as an e-mail attachment.
Open the initial RadFlowDocument again
Use RadFlowDocumentEditor to ReplaceText again with a different value
Now I can't serialize the RadFlowDocument because it is open on my machine.
I'm using C# and Blazor
Code Sample (This is mostly from https://github.com/telerik/document-processing-sdk/blob/master/WordsProcessing/GenerateDocument/DocumentGenerator.cs)
private RadFlowDocument _document;
protected void OnMySendCommand(GridCommandEventArgs args)
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(_document);
editor.ReplaceText("Invoice_Number", "T1234567", false, false);
byte output = File.ReadAllBytes(newFileName + ".docx");
InsertEmail("firstname.lastname@example.org", "Test word file", "Test 1234567", output, "T1234567", true);
editor = new RadFlowDocumentEditor(_document);
editor.ReplaceText("Invoice_Number", "T9999", false, false);
byte output2 = File.ReadAllBytes(newFileName + ".docx"); //Error now says: The process cannot access the file 'E:\Workspace\Intranet\CPE\CPE\Pages\Classes\Invoices\InvoiceTemplate2.docx' because it is being used by another process.
//To Be Clear - it did replace the text and save it to my machine but now can't access the file because it is in use.
//If necessary, I could save each file with a different file name. But I would still want to close them programmatically.
Thanks for any help!