This is not a structured storage file- while opening .xls (2003to97)

Hi,

I am having problem with accessing (open) file which exists on server(SharePoint library) once it's opened, i need to create thumbnail for the uploaded doc. I am using below syntax but it's throwing error.

Exact error is "This is not a structured storage file".

however when i use system path directly like
excelDocument1.Open("c:\\23 KB_xls" , FileFormatType.Excel97To2003); it works fine but this is not my requirement. i have to read document from share point library itself.

Code:

Aspose.Cells.Workbook excelDocument = new Aspose.Cells.Workbook();

WebClient Client = new WebClient();

Client.UseDefaultCredentials = true;

byte[] byteArray= Client.DownloadData(uploadedDocPath);

MemoryStream stream = new MemoryStream(byteArray);

excelDocument1.Open(stream, FileFormatType.Excel97To2003);

excelThumbnail.AddExcelThumbnailsToLibrary(item, excelDocument, objSPWeb, uploadedDocPath, workbookID);

Can anyone help me in opening file, i have also attached .xls document which is throwing error.




Hi,

Well, I am afraid, you got to write your own web parts when using Aspose.Cells for .NET on SharePoint. I suspect there might be an issue with getting the file into streams in your code, so, you should debug and evaluate the following lines of code, the file might not be obtained into streams fine:

byte[] byteArray= Client.DownloadData(uploadedDocPath);

MemoryStream stream = new MemoryStream(byteArray);

You may simply use the following sample code that should work fine so you should fix your issue by yourself accordingly.

e.g.

Sample code:

…

//Using memory stream

byte[] data = File.ReadAllBytes(“23 KB_xls”);

MemoryStream stream = new MemoryStream(data);

excelDocument1.Open(stream, FileFormatType.Excel97To2003);

Thank you.

Hi,

Thanks for your quick reply, i tried below code ie

byte[] data = File.ReadAllBytes("23 KB_xls");

But getting error like Could not find file 'c:\windows\system32\inetsrv\23 KB_xls'.
because this document is not saved anywhere in system, its only available in share point library.


Is there any other way to resolve this issue??

Hi,

Thanks for your posting and using Aspose.Cells.

Please search on the internet how to read your file into byte array from shared point library. Once you have a byte array, you can convert into MemoryStream object and then from MemoryStream object you can create Workbook object and start using Aspose.Cells APIs.

Please see the following sample code and comments for your reference.

C#
string filePath = @“D:\Downloads\source.xlsx”;

//Your job is to read your sharepoint file in bytes
byte[] bytes = File.ReadAllBytes(filePath);

//Then you can convert your bytes into memory stream
MemoryStream ms = new MemoryStream(bytes);
ms.Position = 0;

Workbook workbook = new Workbook(ms);
workbook.Save(“output.xlsx”);


Hi,

I am using below code to read data from share point library and this code runs perfectly for other files (.pdf, .xlsx, .jpg, .ppt, .doc) only with the case of .xls(2003to97) its throwing error that "This is not a structured storage file"
when i try to open workbook.

using (SPSite docsite = new SPSite(uploadedDocPath))
{
using (SPWeb docweb = docsite.OpenWeb())
{
SPListItem item = docweb.GetListItem(uploadedDocPath);
SPFile objspFile = item.File;

byte[] byteArray = objspFile.OpenBinary();

Stream stream = new MemoryStream(byteArray)
Workbook excelDocument = new Workbook();
excelDocument.Open(stream, FileFormatType.Excel97To2003);
}
}

Please help.

Hi,

Thanks for your posting and using Aspose.Cells.

Probably this file has some very old format which is not supported by Aspose.Cells. Could you please share your file for our investigation. We will look into it and help you asap.

I have attached two (.xls) files, none of the attached file is working in our case.


Please do investigate and let us know so, we can close this issue as soon possible.

Hi,

Thanks for your posting and using Aspose.Cells.

You can detect the format of your excel files using the following code.

C#
string filePath = @“D:\Downloads\23+KB_xls.xls”;

var o = FileFormatUtil.DetectFileFormat(filePath);

Also, I have tested your files with the following code with the latest version: Aspose.Cells
for .NET v8.6.0.2
and it did not throw any exception. So you should download and try the latest version to check if your issue is resolved with this or not.

C#
string filePath = @“D:\Downloads\23+KB_xls.xls”;

Workbook workbook = new Workbook(filePath);

Hi ,

I tried using version (Aspose.Cells for .NET v8.6.0.2 ) but unfortunately no luck, i have already mentioned in the above post that to read file from server is not the issue , i am able to open file from server location but when i read document from share point library then pass that stream as a parameter it throws exception :

Error: This is not a structured storage file.

using (SPSite docsite = new SPSite(uploadedDocPath))
{
using (SPWeb docweb = docsite.OpenWeb())
{
SPListItem item = docweb.GetListItem(uploadedDocPath);
SPFile objspFile = item.File;

byte[] byteArray = objspFile.OpenBinary();

Stream stream = new MemoryStream(byteArray)
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
Workbook excel = new Workbook(stream, loadoption);
}
}

We have deadline in 2/3 days, please try above code and let us know is that issue with
aspose cell or in our code?

Please suggest.



Hi,

Thanks for your posting and using Aspose.Cells.

Please try the following change and see if it makes any difference. Changes are highlighted in red color.

C#

using (SPSite docsite = new SPSite(uploadedDocPath))
{
using (SPWeb docweb = docsite.OpenWeb())
{
SPListItem item = docweb.GetListItem(uploadedDocPath);
SPFile objspFile = item.File;

byte[] byteArray = objspFile.OpenBinary();

MemoryStream stream = new MemoryStream(byteArray)
stream.Position = 0;
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
Workbook excel = new Workbook(stream, loadoption);
}
}

Hi,


Still facing the same error issue after adding below code.

Please help here to resolve the issue soon.



Hi,

Thanks for your feedback and using Aspose.Cells.

Please try the following code, this same code as yours except that it uses OpenBinaryStream() method changes are highlighted in red.

C#
using (SPSite docsite = new SPSite(uploadedDocPath))
{
using (SPWeb docweb = docsite.OpenWeb())
{
SPListItem item = docweb.GetListItem(uploadedDocPath);
SPFile objspFile = item.File;

byte[] byteArray = objspFile.OpenBinaryStream();

Stream stream = new MemoryStream(byteArray)
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
Workbook excel = new Workbook(stream, loadoption);
}
}

Hi,


Tried suggested code but sill nothing happened, getting same error message.

Any kind of quick help would be appreciated as i have already spent 3 days on this issue.

Hi,

Thanks for your posting and considering Aspose.Cells.

Please let us know the complete statck trace of your exception and also let us know if you get this error with any type of excel files or if there is some special excel file which is causing this exception.

Please see, there is no error in the following code

Stream stream = new MemoryStream(byteArray)
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
Workbook excel = new Workbook(stream, loadoption);

All the error is present inside this code, so if you could fix it your issue will be resolved

byte[] byteArray = objspFile.OpenBinaryStream();

Somehow you are getting the problem of getting the wrong byte array.which is causing all the issue.

Please also let us know which component you are using

  • Aspose.Cells for .NET
  • Aspose.Cells for SharePoint

As i already mentioned above that i using .xls (97to2003) file and it works perfectly for other excel formats, i have been getting error only with this format .

It (.xls97to2003) also works fine if i give system storage path. I can understand the issue is only with byte stream or may be converted byte stream from share point path is not being supported by Aspose cell.

Currently i using Aspose cell for .net .

Please find below stack trace message:

System.InvalidOperationException: This is not a structured storage file.
at …ctor(BinaryReader )
at .(Stream )
at …ctor(Stream )
at .(Stream )
at Aspose.Cells.Workbook.(Stream , LoadOptions , Boolean )
at Aspose.Cells.Workbook…ctor(Stream stream, LoadOptions loadOptions)


Hi,

Thanks for your clarification and using Aspose.Cells.

It means your code is working fine with some of excel file (xls) but not working for other formats like xlsx etc.

So this exception might be causing because of this line

Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);

Because this line will not work if excel format is XLSX, for xlsx the code should be like this

Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx);

It is better you first detect the load format of your excel file using the following code. Please incorporate your code in the main code and try again.

C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;

byte[] bytesArray = File.ReadAllBytes(filePath);

MemoryStream ms = new MemoryStream(bytesArray);

FileFormatInfo info = FileFormatUtil.DetectFileFormat(ms);

LoadOptions opts = new LoadOptions(info.LoadFormat);

Workbook workbook = new Workbook(ms, opts);



Thanks for your reply, i don’t have any issue with .xlsx file only .xls(97to2003) is creating issue, using above code i m unable to get correct file format, its giving info object value - “unknown” .


error: This file’s format is not supported or you don’t specify a correct format.

SPListItem item = docweb.GetListItem(uploadedDocPath);

SPFile objspFile = item.File;

byte[] bytesArray = objspFile.OpenBinary();

MemoryStream ms = new MemoryStream(bytesArray);

Aspose.Cells.FileFormatInfo info = Aspose.Cells.FileFormatUtil.DetectFileFormat(ms);

Aspose.Cells.LoadOptions opts = new Aspose.Cells.LoadOptions(info.LoadFormat);

Workbook excel = new Workbook(ms, opts);

Please post example from share point storage file as i already mentioned above that it(.xls97to2003) works fine with system storage path only having issue with reading file from share point library.


Hi,

Thanks for your posting and using Aspose.Cells.

Please answer this questions for confirmation

1 - Does your problem occur with all types of xls and xlsx files?
2 - Does your problem occur with only some of xls and xlsx files?
3 - Please attach your xls/xlsx files which are not causing this exception
4 - Please attach your xls/xlsx files which are causing this problem.

Also now we will have to setup the environment to replicate your issue. Could you please let us

1 - Prerequisites of SharePoint
2 - Does it need SQ:L Server
3 - Does it need Visual Studio

It will be helpful if you could provide us detail steps which could help us prepare the setup which we could use to replicate this issue. Thanks for your cooperation.

Hi,


Thanks for responding us.

Answer:
1 - Does your problem occur with all types of xls and xlsx files? : - only with (.xls97to2003)
2 - Does your problem occur with only some of xls and xlsx files? :- only with (.xls97to2003)

Note: Not facing any issue with any kind of .xlsx file and .xls file only the format (.xls97to2003) creating problems.

Steps to setup share point environment
1 - Prerequisites of SharePoint -Install SharePoint 2013
2 - Does it need SQ:L Server - Install SQL server 2012
3 - Does it need Visual Studio- Visual studio 2012

Steps to reproduce issue:
1) Create any custom share point library.
2) Upload any kind of .xls(97to2003) document.
3) In visual studio add a new project also add Aspose cell reference.
4) Write a code to read uploaded document.
5) Create workbook abject for that document

Code we are using:

string uploadedDocPath = “Document path uploaded in share point library”;

using (SPSite docsite = new SPSite(uploadedDocPath))
{
using (SPWeb docweb = docsite.OpenWeb())
{
SPListItem item = docweb.GetListItem(uploadedDocPath);
SPFile objspFile = item.File;

byte[] bytesArray= objspFile.OpenBinary();

Stream ms = new MemoryStream(bytesArray);

string extn = objspFile.Name.Substring(objspFile.Name.IndexOf(".") + 1);
if (extn ==“xls”)
{
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
Workbook excel = new Workbook(ms, opts);
}
else if (extn ==“xlsx”){
Workbook excel = new Aspose.Cells.Workbook(stream);
}
}
}

We are getting error in this line of code : Workbook excel = new Workbook(ms, opts)
that This is not a structured storage file.

Please let me know if any other information is needed.


Hi,

Thanks for your detail instructions and using Aspose.Cells.

I have analyzed your having_issue.xls file and found it has wrong extension, it’s extension should be xlsx not xls.

So changing its name having_issue.xls to having_issue.xlsx will resolve your issue.

I have described the issue in detail in the word document attached with this post. Please read it to resolve this issue.