1

I have a method:

public static string UnZipStr(byte[] input)
{
    if (input == null){
        return null;
    }
    using (MemoryStream inputStream = new MemoryStream(input))
    using (DeflateStream gzip = new DeflateStream(inputStream, CompressionMode.Decompress))
    using (StreamReader reader = new StreamReader(gzip, System.Text.Encoding.UTF8))
    {
        return reader.ReadToEnd();
    }
}

But I always get xml text unzipping, it is fact. I need to change this method in order to return SqlXml object. Unfortunate I'm java developer and cannot solve this task.

Mikhail
  • 1,583
  • 5
  • 22
  • 34

1 Answers1

1

Do you need a SqlXml object or an XmlDocument/XDocument object? This post about converting a SqlXml object into an XmlDocument may be related to your needs.

You may be able to do the following:

public static string SqlXmlFromZippedBytes(byte[] input)
{
    if (input == null){
        return null;
    }
    using (MemoryStream inputStream = new MemoryStream(input))
    using (DeflateStream gzip = new DeflateStream(inputStream, CompressionMode.Decompress))
    using (StreamReader reader = new StreamReader(gzip, System.Text.Encoding.UTF8))
    {
        return new SqlXml(reader); // From System.Data.SqlTypes
    }
}

Here is the documentation on the SqlXml constructor.

Community
  • 1
  • 1
Ryan
  • 7,835
  • 2
  • 29
  • 36