ASPOSE.SLIDE in web service get 'Unable to read entire header' all the time

Hi,

We are trying to use aspose.slide in our online product. For some reason, we have to create web service to do it.

We sent a Byte array, which is the PPT file binary, to the webservice and doing something on the web service server.

We tried code like this:

public String saveFile(byte[] filebyte, String filename, String LessonID)

{

MemoryStream ms = new MemoryStream(filebyte);

Presentation pres = new Presentation(ms);

....

And it fail with "Unable to read entire header; 0 bytes read; expected 512 bytes"

and then we tried

MemoryStream ms = new MemoryStream(filebyte);

try

{

if (File.Exists(myfile))

{

File.Delete(myfile);

}

FileStream fs = new FileStream(myfile, FileMode.OpenOrCreate);

// write the memory stream containing the original

// file as a byte array to the filestream

ms.WriteTo(fs);

ms.Position = 0;

fs.Position = 0;

// clean up

ms.Flush();

ms.Dispose();

ms.Close();

Presentation pres = new Presentation(fs);

fs.Flush();

fs.Dispose();

fs.Close();

...

Failed with similiar error.

Then this

MemoryStream ms = new MemoryStream(filebyte);

try

{

if (File.Exists(myfile))

{

File.Delete(myfile);

}

FileStream fs = new FileStream(myfile, FileMode.OpenOrCreate);

ms.WriteTo(fs);

ms.Position = 0;

fs.Position = 0;

// clean up

ms.Flush();

ms.Dispose();

ms.Close();

fs.Flush();

fs.Dispose();

fs.Close();

//File.WriteAllBytes(myfile, filebyte);

FileStream fs2 = new FileStream(myfile, FileMode.Open,FileAccess.ReadWrite);

Presentation pres = new Presentation(fs2);

...

Same error

All the methods can work in windows function or web application function. Just wrong for web service.

And I found, when you do something to the ppt file after you write it to the server and before you open it again, you can successfully create new ASPOSE.Presentaion. For example, I make a break before the filestream open the ppt file for aspose.presentation, and then I open the ppt file using powerpoint, doing nothing and then close the ppt file. The Presentation pres = new Presentation(fs2); will work.

Even I can delete the temporory ppt file and copy a same name one in same folder, it will work as well.

I believe file handle is not release so there is this problem although I can delete it. Do your guys have any suggestions?

Hello

First try this

MemoryStream ms = new MemoryStream(filebyte);
ms.Position = 0;
Presentation pres = new Presentation(ms);

Or try explicitly closing handle. e.g.

//On reading
FileStream fin = new FileStream(@"C:\Test\right.ppt", FileMode.Open, FileAccess.Read);
Presentation pres = new Presentation(fin);
fin.Close();

//On writing
FileStream fout = new FileStream(@"C:\Test\out4.ppt", FileMode.Create, FileAccess.Write);
pres.Write(fout);
fout.Close();

Also, try the latest version of Aspose.Slides for .NET 3.1.1.1