Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Jul 29, 2015 11:43 am

Hi support,

My company uses Spire.Doc library (v 4.6.28.3041) to parse word templates from SharePoint library. And on one server we have one issue which is not present on another servers. Also i can't reproduce this issue locally. Exception occurs when trying to load word document from Stream:

Code: Select all
System.Runtime.InteropServices.ExternalException (0x80030050): Can't open storage on LockBytes.
   at ?..ctor(Stream A_0, STGM A_1)
   at ?.?(Stream A_0)
   at ?..ctor(Stream A_0)
   at Spire.Doc.Document.LoadFromStream(Stream stream, FileFormat fileFormat, String password)


Do you know why this exception can happen so i will be able to continue my investigation?

ant
 
Posts: 10
Joined: Mon Sep 23, 2013 1:58 pm

Thu Jul 30, 2015 5:49 am

Hello,

Thanks for your inquiry.
Could you please offer us your sample file and your code snippet?
And the better to tell us the detail of your sever configuration which occurred the exception.
It would be helpful to replicate the issue and work out the solution for you ASAP.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Thu Jul 30, 2015 1:47 pm

My code is:

Code: Select all
var fileStream = item.File.OpenBinaryStream();
_clientContext.ExecuteQuery();
_document = new Document();
var formats = new[] { FileFormat.Docx2010, FileFormat.Docx, FileFormat.Doc, FileFormat.Dot };
_document.LoadFromStream(stream, fileFormat);


Document i have problem with:
https://www.dropbox.com/s/6kj213w8otooo ... .docx?dl=0
If i delete some amount of text from it begins to work.

What do you mean by server configuration?

ant
 
Posts: 10
Joined: Mon Sep 23, 2013 1:58 pm

Fri Jul 31, 2015 6:36 am

Hello,

Thanks for your information.
I have tested your issue with latest Spire.Doc( Spire.Doc Pack(hot fix) Version:5.5.28) in our server. It worked well in our side. Please try it.
The server configuration means like the below information.
Windows Server 2008 R2 Standard
Intel Xeon E5-2630 0 @ 2.3GHz
8GB RAM
64-bit

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Fri Jul 31, 2015 12:45 pm

Our server configurattion is:
Code: Select all
Windows Server 2012 R2 Standard
Inter(R) Xeon(R) CPU E5-2697 v2 @ 2.70Ghz 3.07Ghz (2 processors)
12GB RAM
64-bit Operating System, x64-based processor


Have you also tested this file loaded from SharePoint?

ant
 
Posts: 10
Joined: Mon Sep 23, 2013 1:58 pm

Mon Aug 03, 2015 10:13 am

Hello,

Thanks for your information.
I have tested your issue with file you provided. It worked well in our side.
The issue may be caused by the file format that you specified. Please try to change the file format to "FileFormat.Auto"
Here is the code for your reference.
Code: Select all
_document.LoadFromStream(stream, FileFormat.Auto);


Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Wed Aug 05, 2015 7:20 am

With FileFormat.Auto i got this exception:

Code: Select all
 ?: Zip exception.Can't locate end of central directory record. Possible wrong file format or archive is corrupt.
   at ?.?(Stream A_0, Boolean A_1)
   at ?.?(Stream A_0, Document A_1)
   at Spire.Doc.Document.?(Stream A_0)
   at Spire.Doc.Document.LoadFromStream(Stream stream, FileFormat fileFormat, String password)

ant
 
Posts: 10
Joined: Mon Sep 23, 2013 1:58 pm

Thu Aug 06, 2015 6:27 am

Hello,

Thanks for your reply.
Please save the stream to a .bin file before you load it, then, send it to us.
It would be helpful to replicate the issue and work out the solution for you ASAP.
Please kindly note that firstly you need to compress it and upload.
Or you can send it to us ( Support@e-iceblue.com ) via email.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Fri Aug 07, 2015 9:33 am

Hello,

Has your issue been resolved? If not,
Please save the stream to a .bin file before you load it, then, send it to us.
It would be helpful to replicate the issue and work out the solution for you ASAP.
Please kindly note that firstly you need to compress it and upload.
Or you can send it to us ( Support@e-iceblue.com ) via email.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Aug 10, 2015 1:48 pm

Here it is. I've crated it on that server.

But it has the same content as docx file

ant
 
Posts: 10
Joined: Mon Sep 23, 2013 1:58 pm

Tue Aug 11, 2015 8:17 am

Hello,

Thanks for your information.
Sorry that I'm afraid that it is difficult to reproduce the issue without same system environment and server configuration with yours. Please compare the server settings with another servers settings which did not present the issue.
In addition, please note that the file format should match the the format of the stream. You can directly set the file format as docx and try it again.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Tue Aug 11, 2015 8:35 am

Our systems supports any document format so it iterates formats collection and tries to load document with every format. So in each iteration it's directly set.

I tried to recreate template from the scratch and got working document. But if i add header, footer or last page previous error occurs. See working template in attachment.

ant
 
Posts: 10
Joined: Mon Sep 23, 2013 1:58 pm

Tue Aug 11, 2015 9:29 am

Hello,

Thanks for your information.
Could you please offer us your full code about loading the file from Stream?
The better to supply a simplified application demonstrates the issue you encountered.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Tue Aug 11, 2015 9:55 am

Code to get file content from share point:
Code: Select all
public Stream GetFileContent(int fileId)
        {
            var item = _list.GetItemById(fileId);

            _clientContext.Load(
                item,
                i => i.File.ServerRelativeUrl);

            try
            {
                _clientContext.ExecuteQuery();
            }
            catch (ServerException ex)
            {
                switch (ex.ServerErrorCode)
                {
                    case SharePointDocumentsErrorCode.ItemNotFoundErrorCode:
                    case SharePointDocumentsErrorCode.ItemDoesNotExistErrorCode:
                        throw new ItemNotFoundException(string.Format("Item with id ={0} does not found", fileId));
                    default:
                        throw;
                }
            }

            var fileStream = item.File.OpenBinaryStream();
            _clientContext.ExecuteQuery();

            return fileStream.Value;
        }


Code to load template:
Code: Select all
public void LoadTemplate(Stream stream)
        {
            bool loaded = false;
            _document = new Document();

            var formats = new[] { FileFormat.Docx2010, FileFormat.Docx, FileFormat.Doc, FileFormat.Dot };

            foreach (var fileFormat in formats)
            {
                _fileFormat = fileFormat;
                stream.Seek(0, SeekOrigin.Begin); // as Spire might have shifted seek position while trying different format

                try
                {
                    _document.LoadFromStream(stream, fileFormat);
                    loaded = true;
                    break;
                }
                catch (Exception exception)
                {
                    var message = exception.Message.ToLower();
                    if (message.Contains("wrong signature")
                        || message.Contains("wrong file format")
                        || message.Contains("wrong word version"))
                        continue; // the only way Spire leaves us to classify the error...
                    throw;
                }
            }

            if (!loaded)
            {
                throw new InvalidOperationException("Unknown file format");
            }

            _templateProcessor = new WordTemplateProcessor(_document);
            _templateProcessor.AnalyzeTemplate();
        }

ant
 
Posts: 10
Joined: Mon Sep 23, 2013 1:58 pm

Wed Aug 12, 2015 9:33 am

Hello,

Thanks for your reply.
Your code about loading the file from Stream in your "LoadTemplate" method is incorrect.
Please change it to the below code.
Code: Select all
   var _document = new Document();
            MemoryStream ms = new MemoryStream();
            stream.CopyTo(ms);   
            _document.LoadFromStream(ms, FileFormat.Auto);


Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.Doc