Welcome to the Xceed Community Sign in | Join | Help
Community Search  

How to zip a dot net 2.0 in-memory datatable or string?

  •  06-10-2008, 4:02 PM

    How to zip a dot net 2.0 in-memory datatable or string?

    I would like to do the following all in memory without writing to disk on the client's machine.

    Zip an in-memory DataTable in .NET 2.0 (C#) to memory (not disk).  Then I'll send it ( string/byte/stream ..  whatever it's called) to our web service.

     I found some code to change the DataTable into a stream, so I think that's the first part. thanks!

     You can use a MemoryStream or a StringWriter with these overloads to keep it all in memory.

     

    string result;
    using (StringWriter sw = new StringWriter()) {
       dataTable.WriteXml(sw);
       result = sw.ToString();
    }

    If you don't actually need a string but read-only, process able XML, it's a better idea to use MemoryStream and XPathDocument:

    XPathDocument result;
    using (MemoryStream ms = new MemoryStream()) {
       dataTable.WriteXml(ms);
       ms.Position = 0;
       result = new XPathDocument(ms);
    }

View Complete Thread
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.