Anyone tried to update a zip file using DotNetZip? Have problem with access denied

I am trying to update a zip file using DotNetZip. The following code is what I wrote (based off a DotNetZip example)

using (MemoryStream ms = new MemoryStream()) { using (ZipFile zip = ZipFile.Read(filename)) { ZipEntry ze = zip["xl/Connections.xml"]; ze.Extract(ms); String xml = Encoding.ASCII.GetString(ms.ToArray()); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); ChangeDSN(doc); zip.UpdateEntry("xl/Connections.xml", doc.OuterXml); zip.Save(); } } 

But this gives an Access to the path is denied error message on the zip.Save() line. If change it so it saves into another file (in the same directory) then it works.

I am assuming it errors because the file is open but i am only following the sample code in the DotNetZip documentation.

Obviously I am doing something stupid but been a long day 🙂

by unigee via /r/csharp

Leave a Reply