[
  {
    "Id": "441086",
    "ThreadId": "212148",
    "Html": "<p>Hello everybody,</p>\r\n<p>I'm currently working on a little piece of software, written in C#, which automates some image manipulation tasks for me.</p>\r\n<p>My work flow is like this:</p>\r\n<p>First you use my GUI to open a folder, select all images you want to edit. After that my code puts all images in an array, does the image manipulation on each image, saves each image to a subfolder on my harddrive, loads all images from FileStream again(write and read is done on purpose) and adds them to a zip file. This zip file is then saved and uploaded to ftp. After all those tasks my program is supposed to delete the created subfolder including all edited images and the zip file in it.</p>\r\n<p>Unfortunately whenever I try to delete the mentioned subfolder, I get an IOException because the images are still in use. After some tracing, I discovered that all files, which were added using the AddEntry(String entryName, Stream stream) command, were still locked and I couldn't delete them. Using AddFile(String path) didn't do the trick either. The files would still get locked.</p>\r\n<p>Now I was wondering: How can I release those handles? It's really annoying, not being able to delete the directory the way I intend to. Maybe someone has an idea on how to solve this. Since I couldn't find a Dispose() command for the files, I had a little trouble so far, getting to my goal.</p>\r\n<p>About my application itself: I'm using .NET 2.0. My program has a GUI which displays the status for the actions mentioned above. The tasks are grouped in three backgroundworker processes (image manipulation and resizing, zip file creation, ftp upload).</p>\r\n<p>Alright, I guess that's about it. If you guys have any more questions, feel free to ask.</p>\r\n<p>And last but not least, here is the part of my code, which works on the zip file.</p>\r\n<div style=\"color:black;background-color:white\">\r\n<pre><span style=\"color:green\">//directory containing the unedited images</span>\r\nString path = &quot;C:\\\\Pics\\\\&quot;;\r\n\r\n<span style=\"color:green\">//contains all edited images as FileInfo</span>\r\nArrayList ResizedImages = <span style=\"color:blue\">new</span> ArrayList();\r\n\r\n<span style=\"color:green\"><span style=\"color:green\">//contains all unedited images as FileInfo</span></span>\r\nArrayList Images = <span style=\"color:blue\">new</span> ArrayList();\r\n\r\n<span style=\"color:blue\">using</span> (ZipFile zip = <span style=\"color:blue\">new</span> ZipFile())\r\n                {\r\n                    Directory.SetCurrentDirectory(path);\r\n                    zip.TempFileFolder = path;\r\n\r\n                    <span style=\"color:green\">//add images to zip</span>\r\n                    <span style=\"color:blue\">foreach</span> (FileInfo f <span style=\"color:blue\">in</span> ResizedImages)\r\n                    {\r\n                        FileStream fileStream = <span style=\"color:blue\">new</span> FileStream(f.Name, FileMode.Open, FileAccess.Read);\r\n                        zip.AddEntry(f.Name, fileStream);\r\n                    }\r\n\r\n                    <span style=\"color:green\">//filename of zip file is created from filename of first image</span>\r\n                    String fileName = ((FileInfo)Images[0]).Name.Substring(0, ((FileInfo)Images[0]).Name.Length - 4);\r\n\r\n                    <span style=\"color:green\">//save zip, catch exception<br></span>                    <span style=\"color:blue\">try</span>\r\n                    {\r\n                        zip.Save((fileName + <span style=\"color:#a31515\">&quot;.zip&quot;</span>));\r\n                    }\r\n                    <span style=\"color:blue\">catch</span> (Exception exc)\r\n                    {\r\n                        MessageBox.Show(exc.ToString());\r\n                    }\r\n                }\r\n</pre>\r\n</div>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-05-10T07:27:19.903-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "441264",
    "ThreadId": "212148",
    "Html": "<p>Where does the delete occur? - the one that fails.&nbsp; I don't see it.</p>\r\n<p>Your situation sounds very straightforward. &nbsp; Do you have a simple test case that reproduces the problem?</p>\r\n<p>DotNetZip has an extensive test suite that includes a bunch of cases that are VERY similar to what you describe....except that the deletion of the directory works. <br>So...&nbsp;I'm gonna need a test case to&nbsp;illustrate this&nbsp;one.</p>\r\n<p>&nbsp;&nbsp;</p>",
    "PostedDate": "2010-05-10T17:35:56.25-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]