This project has moved. For the latest updates, please go here.

DocX.Save(Stream) - should it be closing the Stream passed in?

Aug 11, 2009 at 6:07 PM

I have a Word document in memory (which I loaded from my database).  I am calling DocX.ReplaceText() to replace stuff and then I call DocX.Save(Stream) and pass in a MemoryStream.  After I do that I read the data out of the MemoryStream and do stuff with it.

The problem is that DocX.Save(Stream) closes the Stream that I passed in.  Should it be doing that?  Anyone passing in a FileStream probably won't mind because they would've just closed it right after the call anyway, but in my case I'm passing in a MemoryStream.  My opinion is that if I pass in a Stream that I opened, then it should be my responsibility to close it when I'm ready to close it.

I modified the DocX code on my machine to not close the Stream and everything works for me now... just thought I'd throw in my $.02.

BTW, DocX is awesome.  I spent a month writing this kind of thing once, so I know how much of a pain it is.  I love not having to write all that anymore!

Jon

Coordinator
Aug 12, 2009 at 8:59 AM
Hi Jon,

I am very happy that you like DocX. You wrote the following

>>My opinion is that if I pass in a Stream that I opened, then it should be my responsibility to close it.
I could not agree with you more, I will make this change in the next version of DocX.

Thank you for contributing,
kind regards and happy coding,
Cathal