none
Bad file for Open XML SDK - rewriting zip makes it good RRS feed

  • Question

  • Hi;

    Sample file at http://www.windwardreports.com/temp/StillBad.zip - I removed the BOM at the beginning. And Open XML still won't open it. But...

    If I write the contents of the docx file out with WinZip and then create a new DOCX file using those files with WinZip - then it works. I don't change the contents of the files at all, I just write them out then read them in to a new zip file.

    WinZip says the original file is good - all diagnostics pass. So why dos Open XML (or packaging) not like the zip file?

    ??? - thanks - dave


    Very funny video - Reporting as a Metaphor
    Wednesday, June 2, 2010 3:46 PM

Answers

All replies

  • Hello Dave,

     

    I can reproduce the issue with the provided file. Very strange. If I extract and rezip the content again. It works. 

    I do some debugging using the .NET Reflector and find where throws the exception,

        private void Load()
        {
          try
          {
            Dictionary<Uri, OpenXmlPart> loadedParts = new Dictionary<Uri, OpenXmlPart>();
            PackageRelationshipCollection relationshipCollection = this._metroPackage.GetRelationships();
            bool flag = false;
            foreach (PackageRelationship relationship in relationshipCollection)
            {
              if (relationship.RelationshipType == this.MainPartRelationshipType)
              {
                flag = true;
                Uri partUri = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), relationship.TargetUri);
                PackagePart part = this.Package.GetPart(partUri);
                if (!this.IsValidMainPartContentType(part.ContentType))
                {
                  OpenXmlPackageException exception = new OpenXmlPackageException(ExceptionMessages.InvalidPackageType);
                  throw exception;
                }
                this.MainPartContentType = part.ContentType;
                break;
              }
            }
            if (!flag)
            {
              OpenXmlPackageException exception2 = new OpenXmlPackageException(ExceptionMessages.NoMainPart);
              throw exception2;
            }
            base.LoadReferencedPartsAndRelationships(this, null, relationshipCollection, loadedParts);
          }
          catch (OpenXmlPackageException)
          {
            this.Close();
            throw;
          }
          catch (Exception)
          {
            this.Close();
            throw;
          }
        }

    The exception is thrown from the OpenXmlPackage.Load() function.  In my debugging, I found this._metroPackage.GetRelationships() returned an empty relationshipCollection. This makes the codes cannot find the MainPartRelationshipType relationship part, so it throws the NoMainPart exception. But I am not sure why GetRelationships() cannot return the exacted existed three relationships in that document. Personally speaking, it looks like a bug for me.

    Indeed, the original file is very special too, I think. So could you please let us know, how do you generate it or where do you get it? Since rezipping the content corrects the issue, I am writing to check if this could be a workaround in your scenario at this time? Or how the issue impacts more in your side?

     

    Have a nice weekend sir!

     

    Best regards,
    Ji Zhou
    MSDN Subscriber Support in Forum


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, June 4, 2010 1:58 PM
    Moderator
  • Hi;

    We create the file with our reporting engine. Re-zipping most definitely will not work for many of our use cases. Can you please tell us what it does not like in the zip file and we will change that. Even if it is a bug, let us know how to write the zip file differently to get around it.

    thanks - dave


    Very funny video - Reporting as a Metaphor
    Friday, June 4, 2010 3:20 PM
  • Hi;

    Any luck finding what we need to do differently so that the packaging code will read our docx file?

    thanks - dave


    Very funny video - Reporting as a Metaphor
    Tuesday, June 8, 2010 5:13 PM
  • I did do some more investigation, but haven't found anything special yet. The document looks like same to me as original one after re-zipping.

    Is it possible to sharing the codes about how the reporting engine genrates the file? I think the file generation part is an important step to investigate the issue.

     

    Best regards,

    Ji Zhou


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, June 9, 2010 11:45 AM
    Moderator
  • I can't give you the full source but I can tell you how we create it - we use ICSharpCode.SharpZipLib.

    Can't you just ask the package dev team to look at it and say what they don't like about it? I think you should tell them as this is probably a bug in their code - and at the same time they can tell me what to do different to work around it.

    thanks - dave


    Very funny video - Reporting as a Metaphor
    Wednesday, June 9, 2010 3:34 PM
  • I found it. When putting files in the zip file, you must do dir/file.ext, not dir\file.ext. Please ask the package dev team to accept both.

    thanks - dave


    Very funny video - Reporting as a Metaphor
    • Marked as answer by DavidThi808 Wednesday, June 9, 2010 11:08 PM
    Wednesday, June 9, 2010 11:07 PM