We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to save currently open document W/O creating new stream?

I have loaded a word document from FileSystem. I update the document. Now i want to Save the documnet. There is no save method that takes NO parameter, all the parameter asks either for new FileName or stream. How do i save the currently open document to itself with out creating new document.

Aspose.Words.Document document = new Aspose.Words.Document(stream);
document.Range.Replace("[Your Name]", "James Smith", true, true);
document.Range.Replace("[Street Address]", "4444 Test Aven", true, true);
document.Range.Replace("[City, ST  ZIP Code]", "San Jose, CA 22222", true, true);
document.Save(); //????There no save method without any parameter

Hi there,
Thanks for your inquiry.
When you open a document from disk using Aspose.Words, it is loaded into memory and stored in a DOM. There is no direct link between the loaded document and the file on disk. In order to save your changes you will need to overwrite the original.
In your case it would be best to create a new instance of a stream using your variable and then save the document to this stream.

so what you are saying even if i close the original stream after creating instance of document object and before performing any operations. it will work?

Stream fs = new FileStream("test.doc");
Document doc = new Document(fs);
// perform some operations using doc here

Thanks for your request. Sure it will work. Aspose.Words reads a whole document into DOM in memory. So after loading the document, you can close the stream.
Best regards,

One way it sounds good becuase resources are not locked down while performing the operations, but on the other hand if the file size is large it could consume lot of memory when mutiple users are working with the files.

1> Is there any setting that would allow us to do some kind of optimization ? any suggestions

2>While loading the document, internally are you reading the whole document at once or reading chunk by chunk. If its chunk by chunk then can we set the chunk size?

Thanks for your request.

  1. The only option you can use is specifying a temporary folder:
    This option decreases using memory upon saving documents to DOC format.

  2. Aspose.Words loads the document at once.

Best regards,