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

Free Support Forum - aspose.com

Aspose constructor

I am creating a new aspose workbook using a memorystream

Aspose.Cells.Workbook wrkBook = new Aspose.Cells.Workbook(memStream);

Then i am when i am trying to access the memorystream

memStream.Position = 0;

it gives me an exception : Cannot access a closed stream.

Does this constructor close the stream and why ??

Please reply, i need help on this


I am not sure how do you get Workbook into memory streams. I have tested your scenario/ case a bit and it works fine. I used a simplest Excel file. I read the file into byte array then initializes the memory stream based on the byte array. I loaded the file via Aspose.Cells APIs based on the memory stream and then check the length of the streams in byte array, it works fine.
Sample code:

FileStream fs = File.Open(@“e:\test2\Book1.xlsx”, FileMode.Open);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
MemoryStream ms = new MemoryStream(buffer);
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
Workbook workbook = new Workbook(ms, loadOptions);

byte[] barray = ms.ToArray();
MessageBox.Show(ms.Length.ToString()); //It provides me the length. -OK

Let us know if you still have any problem.

Thank you.

Can we again read from the same stream.

Workbook workbook = new Workbook(ms, loadOptions);
ms.position = 0 ->> This gives me an expection.

Memorystream is unreadable after creating a workbook. Can’t we resue the same stream after calling the constructor ??

MemoryStream is getting disposed, i cannot access the same stream and write it to 2 different file. Please let me know if you need any more details.


Could you provide us complete sample code (runnable) same as mine in my previous post to evaluate your issue properly.

Thank you.