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

Free Support Forum - aspose.com

Questions about Aspose.Words and filesize of Document

How do i access the Bytes property of Document.BuiltInDocumentsProperties if this doesnt work: int intT = doc.BuiltInDocumentsProperties.Bytes?
J

Hi
Thanks for your inquiry. This property does not work because file size is dependent on the SaveFormat. For example file size of DOC and DOCX files will be different. If you need to get size of the file you can try saving document into the stream and get its length as shown in the following code:

// Create Document and DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert some content into the file
for (int i = 0; i < 100; i++)
{
    builder.Writeln("This is line of text.");
}
// Create MemoryStream and save Document into this stream
MemoryStream docStream = new MemoryStream();
doc.Save(docStream, SaveFormat.Doc);
// Get size of stream
long bytes = docStream.Length;

I hope this could help you.
Best regards.

Thanks alexey, I noticed that when i ran my version the bytes where 780123 but on the file on the disk is like 738,816. Any idea why it might be off a little?
Also, since we are saving the doc with doc.Save, how would we remove that same doc?

Hi
Thanks for your inquiry. I tested this and values are the same. Here is code:

// Get size of stream
int bytes = (int)docStream.Length;
doc.Save(@"Test102\out.doc");
int fileSize = File.ReadAllBytes(@"Test102\out.doc").Length;
Assert.AreEqual(bytes, fileSize, "Should be the same");

Best regards.

Thank you for the assistance Alexey. It was very helpful.