Sto lavorando in C# e sto scaricando per Internet un file zip contenente un file XML. e desidero caricare questo file XML. Questo è quello che ho finora:Decompressione di un flusso in C#
byte[] data;
WebClient webClient = new WebClient();
try {
data = webClient.DownloadData(downloadUrl);
}
catch (Exception ex) {
Console.WriteLine("Error in DownloadData (Ex:{0})", ex.Message);
throw;
}
if (data == null) {
Console.WriteLine("Bulk data is null");
throw new Exception("Bulk data is null");
}
//Create the stream
MemoryStream stream = new MemoryStream(data);
XmlDocument document = new XmlDocument();
//Gzip
GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress);
//Load report straight from the gzip stream
try {
document.Load(gzipStream);
}
catch (Exception ex) {
Console.WriteLine("Error in Load (Ex:{0})", ex.Message);
throw;
}
in document.Load
sto ottenendo sempre la seguente eccezione:
Il numero magico nell'intestazione GZip non è corretto. Assicurati di passare un flusso GZip.
Cosa sto facendo male?
State scaricando un 'gzip' o un' Zip'? I due non sono la stessa cosa. – Oded
'zip! = Gzip' - Vedi http://en.wikipedia.org/wiki/Gzip e http://en.wikipedia.org/wiki/ZIP_%28file_format%29 – Polynomial
Immagino che questo sia il mio primo errore. È un file zip non Gzip. –