Free Support Forum - aspose.com

Error when openning a memorystream as a Excel 2007 xlsx Workbook

Hi!

I have just donwloaded the Aspose.net total for testing purpose. I want to convert an xlsx file to a pdf file. I have a memory stream (ms) that represent an xlsx file and I get an error when trying to open:

w.Open(ms, FileFormatType.Excel2007Xlsx); //Error : EndOfStreamException

if I Add this line before openning "ms.Position=0;" then I get the error "NullReferenceException"

So in both case I cannot open my memorystream.

Any help!

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, I checked you code with the attached latest version of Aspose.Cells and it works fine. Please try the attached latest version and if you still face any problem, please share your template file and sample code to reproduce the issue and we will check it soon. Also, following is my sample code for your reference:

////Create a Stream object

FileStream fstream = new FileStream("D:\\Test_Temp\\book2.xlsx", FileMode.Open);

byte[] Data = new Byte[fstream.Length];

////Obtain the file into the array of bytes from streams.

fstream.Read(Data, 0, Data.Length);

//Instantiating a Workbook object

Workbook workbook = new Workbook();

MemoryStream ms = new MemoryStream(Data);

//Open the template workbook

workbook.Open(ms,FileFormatType.Excel2007Xlsx);

//Save the workbook

workbook.Save("D:\\Test_Temp\\Check.pdf",FileFormatType.Pdf);

Thank You & Best Regards,

Hi!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your answer.

I still have the same problem. Here is the code you sent me, I just modified the input file:

////Create a Stream object

FileStream fstream = new FileStream("c:\\windows\\temp\\tt.xlsx", FileMode.Open);

byte[] Data = new Byte[fstream.Length];

////Obtain the file into the array of bytes from streams.

fstream.Read(Data, 0, Data.Length);

//Instantiating a Workbook object

Workbook workbook = new Workbook();

ms = new MemoryStream(Data);

//Open the template workbook

workbook.Open(ms, FileFormatType.Excel2007Xlsx); //Here is the error NullReferenceException

Find attached the xlsx file tt.xlsx.

Regards,

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

We have found your mentioned issue after an initial test. We will look into it and get back to you soon. Your issue has been registered in our internal issue tracking system with issue id CELLSNET-13615.

Thank you & Best Regards,

Hi!

I'm sorry to speed you but the fact is I am evaluating some development tools because I need them for some current development work. I'm sure that your product Aspose total for .net (OEM dev licence) can meet my requirements as I need to generate Excel and Word files, to convert them to PDF, to manage incoming and outgoing emails, and so on. But the problem is that I can not buy your product if the first thing I'm trying does not work.

Anyway, I have to chose my dev tools very quickely because I need to start development at the beginning of next week. Do you know when you will be able todeliver a corrected Cells.net? Are you sure you will correct it ?

I think I'd prefer work with your product than working with some of your concurrents but how can I do?

What do you think?

Hi,

Please try the attached version. We have figured it out.

Thank you.

Hi,

Thank yo for your answer.

The openning is working now but I have a problem for converting/saving. (Attached file)

Here is the code :

FileStream fstream = new FileStream("c:\\windows\\temp\\tt.xlsx", FileMode.Open);

byte[] Data = new Byte[fstream.Length];

////Obtain the file into the array of bytes from streams.

fstream.Read(Data, 0, Data.Length);

//Instantiating a Workbook object

Workbook workbook = new Workbook();

MemoryStream ms2 = new MemoryStream(Data);

//Open the template workbook

workbook.Open(ms2, FileFormatType.Excel2007Xlsx); //This line is working now with the new version of cells.net

workbook.Save("c:\\windows\\Temp\\Check.pdf", FileFormatType.Pdf); //Here appears the error

Here is the error (of course the folder I try to wright to has "total control" granted for "all users" in the security options)

Echec de la demande d'autorisation de type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I have the same error if I try to convert to a new memorystream (ms) instead of a file with these lines of code

ms = new MemoryStream();

workbook.Save(ms, FileFormatType.Pdf); //Here appears the error, the same as when I try to convert to a file

Any idea?

Hi,

Well, the issue seems to be of security permission settings for the IO operation and does not concern to Aspose.Cells for .NET component, We think you are not allowed to access/manipulate the file system completely. To confirm this exception, you may try to open/save the file using File Streams without involving Aspose.Cells for .NET API.

I think you need to modify the proper security settings for your requirements. You may try to assign Administrative role for your application.

Thank you.

Well, excuse me but I don't understand. When I try to convert the workbook to a new memorystream (that has nothing to do with the file system) I get the same error.

So that is not a problem with the file system!

Don't you think?

Hi,

Well, I tested your issue both ways using your template Xlsx file. I have used a sample WinForm and an Asp.NET sample application and both work fine here. I tested it on WinXp test VS.NET projects. The exception "System.Security.Permissions.FileIOPermission " refers to the permissions set you got and it is IO type error. If you are on Windows Server 2003, then make sure that the Network Service account has sufficient permissions set to the site/directory and all of its files and subdirectories etc. Also, you may check your ASPNet account if you are using a web project.

Here is my sample code that works both in windows and web projects:

Workbook workbook = new Workbook();

workbook.Open("e:\\test\\tt.xlsx");

MemoryStream ms = new MemoryStream();

workbook.Save(ms, FileFormatType.Pdf);

ms.Seek(0, SeekOrigin.Begin);

byte[] buffer = new byte[ms.Length];

buffer = ms.ToArray();

FileStream fs = new FileStream("e:\\test\\outFile.pdf", FileMode.Create);

fs.Write(buffer, 0, buffer.Length);

fs.Close();

ms.Close();

If you still could not evaluate, kindly create a simple project, zip it and post it here with all the details about your environments etc.

Thank you.

Hi,

Sorry to bother you but I still have the same error. I have created a new project (web site) with Visual Studio 2008 with the code you sent me inserted in the page_load of the start page code behind (default.aspx.cs). See attached zip file.I have created a new directory c:\test adding permission to all users having full access to that directory. I am using Windows 7 64 bit. I use to read/write files with all of my web apps and have never seen such an error while trying to open a document. I don't understand. The error appears on the line

workbook.Open("c:\\test\\tt.xlsx");

Échec de la demande d'autorisation de type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Thank you for your help...

System info

Nom du système d’exploitation Microsoft Windows 7 Édition Intégrale
Version 6.1.7600 Numéro 7600
Autre description du système d’exploitation Non disponible
Fabricant du système d’exploitation Microsoft Corporation
Ordinateur OSIRIS
Fabricant INTEL_
Modèle DX58SO__
Type PC à base de x64
Processeur Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz, 2661 MHz, 4 cœur(s), 8 processeur(s) logique(s)
Version du BIOS/Date Intel Corp. SOX5810J.86A.3435.2009.0210.2311, 10/02/2009
Version SMBIOS 2.5
Répertoire Windows C:\Windows
Répertoire système C:\Windows\system32
Périphérique de démarrage \Device\HarddiskVolume1
Option régionale France
Couche d’abstraction matérielle Version = "6.1.7600.16385"
Utilisateur Osiris\Jessy
Fuseaux horaires Paris, Madrid
Mémoire physique (RAM) installée 6,00 Go
Mémoire physique totale 5,99 Go
Mémoire physique disponible 3,38 Go
Mémoire virtuelle totale 12,0 Go
Mémoire virtuelle disponible 8,60 Go
Espace pour le fichier d’échange 5,99 Go
Fichier d’échange C:\pagefile.sys

VS info

Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.5 SP1

Installed Edition: Professional

Microsoft Visual C# 2008 91605-270-2711136-60689
Microsoft Visual C# 2008

Microsoft Visual Studio 2008 Tools for Office 91605-270-2711136-60689
Microsoft Visual Studio 2008 Tools for Office

Microsoft Visual Studio Tools for Applications 2.0 91605-270-2711136-60689
Microsoft Visual Studio Tools for Applications 2.0

Microsoft Visual Web Developer 2008 91605-270-2711136-60689
Microsoft Visual Web Developer 2008

Crystal Reports AAJ60-G0MSA4K-68000CF
Crystal Reports Basic for Visual Studio 2008


Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB944899) KB944899
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/944899.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947171) KB947171
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947171.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947180) KB947180
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947180.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB948127) KB948127
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/948127.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB953256) KB953256
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/953256.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB971091) KB971091
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/971091.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB971092) KB971092
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/971092.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB973674) KB973674
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/973674.

Hotfix for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB945282) KB945282
This hotfix is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/945282.

Hotfix for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB946040) KB946040
This hotfix is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946040.

Hotfix for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB946308) KB946308
This hotfix is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946308.

Hotfix for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB946344) KB946344
This hotfix is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946344.

Hotfix for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB946581) KB946581
This hotfix is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946581.

Hotfix for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB947173) KB947173
This hotfix is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947173.

Hotfix for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB947540) KB947540
This hotfix is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947540.

Hotfix for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB947789) KB947789
This hotfix is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947789.

Microsoft Visual Studio 2008 Professional Edition - ENU Service Pack 1 (KB945140) KB945140
This service pack is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/945140.

Security Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB973675) KB973675
This security update is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this security update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/973675.

Security Update for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU (KB972222) KB972222
This security update is for Microsoft Visual Studio 2008 Shell (integrated mode) - ENU.
If you later install a more recent service pack, this security update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/972222.

SQL Server Analysis Services
Microsoft SQL Server Analysis Services Designer
Version 10.0.2531.0

SQL Server Integration Services
Microsoft SQL Server Integration Services Designer
Version 10.0.2531.0 ((Katmai_PCU_Main).090329-1015 )

SQL Server Reporting Services
Microsoft SQL Server Reporting Services Designers
Version 10.0.2531.0

Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB956453) KB956453
This update is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/956453.

Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB967143) KB967143
This update is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/967143.

Just some more information about my last message.

I reinstalled cells.net using the command line (running as administrator) as described in your help, because it says that some installation of your product may lead to file system error besause of a directory created by the installer for web demo.

I modified my c# code to add a section that modifies an existing text file in the same directory where is stored the Excel file that shoul be converted to PDF. (See attached)

The modification of the text files works properly. So, it seems that I don't have any access problem to my file system.

Let me know...

Hi,



Could you try to manually use File Streams to open your template xlsx
file from the path and save as the file without involving Aspose.Cells
APIs and response to the client browser to check if you got same
security permission error on opening/saving the template file now.



e.g.



FileStream fs1 = new FileStream(“c:\test\tt.xlsx”, FileMode.Open);

byte[] data1 = new byte[fs1.Length];

fs1.Read(data1, 0, data1.Length);

this.Response.ContentType = “application/xlsx”;

Response.AddHeader( “content-disposition”,“attachment; filename=outt2.xlsx”);

Response.BinaryWrite(data1);

Response.End();

Hi,

I've done the test and everything works fine. You can find attached : the projet (zip file), the screenshot and the output file.

Regards,

Hi,

Please confirm us where you got the security permission error, I mean on Workbook.Open() or Workbook.Save() method.

It looks very strange to us as we have tested it on several machines (32-bit and 64-bit) and it works absolutely fine without any issue. We still persist this is security permissions set error and nothing to do with the component. To rectify this issue one has sufficient rights to access/manipulate file system.

We have conducted a fresh test using your xlsx file on Windows 7 64-bits OS with the following code in a web project.

Sample code:

protected void Page_Load(object sender, EventArgs e)
{
Workbook workbook = new Workbook();
workbook.Open(@“D:\test\tt.xlsx”);
workbook.Save(@“D:\test\dest.pdf”);
}
}




Attached is our resultant pdf file for your reference.


Thank you.

Hi,

The error is on workbook.open() method.

As you can see in my precedent message, I can create, modify and write files without any problem in my c\\test directory.

Your cells.net help says that there can be problem with the file system if the component is not installed with administrator privilege. That is why I uninstalled it and reinstall with administrator privilege from the command line.

The file io problem appears on workbook.open. Does your component use the virtual directory Aspose.Celles.Demo. Indeed, as you can see in the attached image, only anonymous authentication is activated? Is it ok?

Does your component need to access another directory for the workbook.open method?

Regards,

Hi,

Aspose.Cells is a pure .NET component created in managed C#. Just for your information, in Workbook.Open method, we use File.OpenRead(fileName) method to get the file stream and in the Workbook.Save method we use File.Create method to create the file stream.

Moreover, in those methods there is neither concerned/written to access/manipulate other directories in the file system what so ever nor it is dependent or affiliated with other part of the file system. We still feel it is very strange issue, we never heard of this kind of issue from our hundreds of users using our product in their most diverse environments / platforms as they are using our component successfully.


Thank you.


Hi,

I've just tested the open, save and convert on my notebook and it is working fine. My notebook is Windows 7 64 bits just like my workstation.

Two questions

1. When I just open and save my xlsx file with workbook.open and then workbook.save, the file created with workbook.save is not the same as the original file. The images are not there, the height of some lines are not like in the original file and some grid lines are visible and some other are not. See attached, the original and the one saved with workbook.save. So the PDF file resulting from the conversion does not reflect my original file (even if it reflects the file saved with workbook.save). Wath do you think?

2. It still does not work on my workstation. I originally installed Aspose total for .net. Do you know wath I shoul do?

Thank you for your help!

Hi,

On my workstation, I uninstalled one by one all the components of Aspose total, then re-installed the cells component just like I did on my notebook. The error is still here. Maybe it will help, here is the stack trace of the error on workbook.open

à System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
à System.Security.CodeAccessPermission.Demand()
à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
à System.IO.File.OpenRead(String path)
à Aspose.Cells.Workbook.Open(String fileName)
à _Default.Page_Load(Object sender, EventArgs e)
à System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
à System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
à System.Web.UI.Control.OnLoad(EventArgs e)
à System.Web.UI.Control.LoadRecursive()
à System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Regards,

Hi,

1.
When I just open and save my xlsx file with workbook.open and then
workbook.save, the file created with workbook.save is not the same as
the original file. The images are not there, the height of some lines
are not like in the original file and some grid lines are visible and
some other are not. See attached, the original and the one saved with
workbook.save. So the PDF file resulting from the conversion does not
reflect my original file (even if it reflects the file saved with
workbook.save). Wath do you think?

We found the issue as you have described. We have logged your issue into our issue tracking system with an issue id: CELLSNET-13799. We will figure it out and get back to you soon.

Thank you.