0

I am serializing an object with the following code, which uses GZip and Xml:

        FileStream fs = new FileStream(destinationfolder + "/myFileName.gz",
                                       FileMode.Create, FileAccess.Write);
        using (var gz = new GZipStream(fs, CompressionMode.Compress)) {
            var serializer = new XmlSerializer(typeof(MyObjectType));
            serializer.Serialize(gz, myObject);
        }

That works fine, with one single problem: The user can open the .gz file with 7Zip (after setting the file association), but then he can't just doubleclick the shown xml inside the .gz file, since it doesn't have the .xml extension (although the content is actually there, xml formatted and all).

Question is: "How can I serialize XML to a GZipStream so that the .xml extension is saved with the file, inside the .gz archive?" I'm using .NET 4.0.

Thanks for reading.

heltonbiker
  • 26,657
  • 28
  • 137
  • 252

1 Answers1

0

I have figure out a simple way to solve that. If this way should be considered a hack or a pragmatic and fine solution, is up to each one, I think.

Simply set the GZip filename to myFileName.xml.gz. This actually makes the inner file appear as myFileName.xml (trimming out the .gz extension as before).

I hope this won't break in the future...

heltonbiker
  • 26,657
  • 28
  • 137
  • 252