How to download and unzip a sitemap gz file in c#?
I need to download and unzip 开发者_StackOverflowa sitemap.xml file that is compressed (maybe tar + gzip?) into a sitemap.xml.gz
From Windows I use 7zip. But note that the gz contains a directory with the same name of the zipped file (maybe due to tar + gx)
How can I do in c#?
Thanks
Use the GZip Stream class to unzip the XML document.
Something like:
var file = File.Open("C:\test.xml.gz", FileMode.Open);
var zip = new GZipStream(file, CompressionMode.Decompress);
var doc = new XmlDocument();
doc.Load(zip);
Edit
To be more clean with our IDisposables:
var doc = new XmlDocument();
using(var file = File.Open("C:\test.xml.gz", FileMode.Open))
using(var zip = new GZipStream(file, CompressionMode.Decompress))
{
doc.Load(zip);
}
精彩评论