FileStream - Can not access a closed File

  • Thread starter Thread starter wapt49
  • Start date Start date
W

wapt49

Guest
Hi,

I tried to create zip with entry xml File. However I got error "Cannot access a closed file". Below is the Code. Can anyone help me why I got this error? Many Thanks

private FileResult createZipFromXmlImport(ImportBase import, string fileName)
{
var zipPath = Path.Combine(ConfigProvider.InfrastructureSettings.BaseDocumentsPath, fileName + @".zip");

using (FileStream fileStream = new FileStream(zipPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
using (ZipArchive archive = new ZipArchive(fileStream, ZipArchiveMode.Update))
{
ZipArchiveEntry zipArchiveEntry = archive.CreateEntry(fileName + @".xml");
using (StreamWriter streamWriter = new StreamWriter(zipArchiveEntry.Open()))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ImportBase));
xmlSerializer.Serialize(streamWriter, import);
return File(fileStream, "application/zip", fileName);
}
}
}
}


Regards

Continue reading...
 
Back
Top