How can I convert Document to Byte...?

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");

I hope that it will help you.

Hello:
Thank you very much. Though I’ve already solved this way:

string appPath = this.MapPath(".");
appPath = System.IO.Path.GetDirectoryName(appPath);
appPath = System.IO.Path.GetDirectoryName(appPath);
string basePath = System.IO.Path.GetDirectoryName(appPath);
basePath = basePath + "\\Archive"; 

doc.Save(basePath + "\\temp.temp", SaveFormat.Doc);
FileStream fsOut = new FileStream(basePath + "\\temp.temp", FileMode.Open, FileAccess.Read, FileShare.None);
byte[] buffer;
buffer = new byte[fsOut.Length];
fsOut.Read(buffer, 0, buffer.Length);
fsOut.Close();
fsOut = null;
File.Delete(basePath + "\\temp.temp");

Thanks-
Razin