Free Support Forum -

Problems with new Document

Hi guys,
Im trying do this:<br><br>public String Exec()<br>{<br> // Get the bin directory.<br> string binDir =<br> Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);<br> // The templates are stored in the directory one level up.<br> string templateDir = Path.GetDirectoryName(binDir);<br> License license = new License();<br> license.SetLicense("C:\\Arquivos de programas\\Aspose\\Aspose.Words\\License\\Aspose.Word.lic");<br> Document doc = new Document(Path.Combine(templateDir, "Template.doc"));<br> return "test";<br>}<br><br>And occurs the problem: Unable to read beyond the end of the flow<br>in the line Document doc = new Document(Path.Combine(templateDir, "Template.doc"));<br><br>I also try: <br>Document doc = new Document("C:\\document.doc");<br>and the same problem...<br>what im doing?

PS: I Get this code in this forum



Thank you for your interest in Aspose products.

This code is correct. Please attach your document so we could reproduce this on our side.


Sorry, i found my error :blush:
The guy who makes the document, uses OpenOffice and save in .doc format… now I make a .doc template from word and it works!


Other question… im doing this to gives a value for merge fields...<br>(i cant use MoveToMergeField and then Write because it replaces the merge field…)…
I see the post Preserving MERGEFIELD identifier
but it doesn`t works, the code below REPLACE the Field… how can I preserve the field name?

Document doc = new Document(@"in.doc"); //Open the template document
string[] names = {"FieldName" };
string[] values = { "FirstUpdate" };
doc.MailMerge.Execute(names, values);
doc.Save(@"out.doc"); //save the report


the file is atached.

This document opens fine. Would you attach the one you had the problem with? We are trying to make our product better so it is valuable for us to experiment with such documents. I see that it was created with OpenOffice, wasn’t it?

A field has "Text" property. You can just assign to it. Doesn't it work for you?

Sample you are posting here is another approach named Mail Megre.

Thank you,

the file with problem is atached.
The code now is:

public String Exec()

License license = new License();
license.SetLicense(“C:\Arquivos de programas\Aspose\Aspose.Words\License\Aspose.Word.lic”);
Document doc = new Document(“C:\document.doc”);
string[] names = { “CAMPO” };
string[] values = { “FirstUpdate” };
doc.MailMerge.Execute(names, values);
//save the report
return sArq;

But this code replace the Field… i just wanna set the value of the field… understand?
Can you send me a template with "A field has “Text” property. "
I make my merge fields in: Insert > Field



Thanks for your inquiry. For mail merge operation to work, the document should contain Word MERGEFIELD. During mail merge operation, merge fields in the document are replaced with values from your data source. Also you can use NonMergeFields. See the following link for more information.

I hope that this will help you. Please let me know if you would like to know something else.

Best regards.

I`ll try give a better explication,

I have a template with some merge fields… and the user can change this document any time.
But when my application generates the FINAL file the aspose replaces the merge fields to the fields values… understand?
What I want is… keep with the merge fields, but in the visualization he will see the field value…
so We can generate the document any time we want,…

Sorry for my bad english…


Thanks for your explanation. I understand what you would like to do. But you can’t achieve this using mergefields. Suggest using bookmarks or text formfields instead.

Best regards.