Hello:
I’ve saved a word document into database. After than I read the docfile from database, set the mail marge fields and displayed in on the aspose viewer as follows:
MemoryStream ms = new MemoryStream(objDocGenTemplate.Document);
Document doc = new Document(ms);
doc.MailMerge.Execute(fieldNames, fieldValues);
Now I need to convert this document into byte[] array. How can I do that? I converted a document to byte[] array this way:
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] document = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
But the problem is it requires filePath. But I don’t have the filePath at this situation. What can I do?
Thanx-
Razin
Hi
Thanks for your request. Try to use MemoryStream to save document after executing mail merge. See the following example.
// open template
Document doc = new Document(@"086_89351_thk_razin\in.doc");
string[] fieldNames = { "Field1" };
string[] fieldValues ={ "Field1Value" };
// execute mail merge
doc.MailMerge.Execute(fieldNames, fieldValues);
// create new stream
MemoryStream stream = new MemoryStream();
// save doc to stream
doc.Save(stream, SaveFormat.Doc);
// get byte array from stream
byte[] document = stream.GetBuffer();
// create new stream and load byte array into it
MemoryStream stream1 = new MemoryStream(document);
// load document from stream
Document doc1 = new Document(stream1);
doc.Save(@"086_89351_thk_razin\out.doc");