Problems updating ZIP file

Nov 14, 2011 at 2:13 PM

Was using, kept getting a message indicating "file in use by another process".  Upgraded to, now getting FileNotFoundException.  Basically given a file \\UNCPath\filename.xml and a file \\UNCPath\ containg a previous version of \\UNCPath\filename.xml entered with the code I will provide, when I produce an new \\UNCPath\filename.xml, I want to put it into the \\UNCPath\

Here's the code.  The bold area is where I'm doing the Add/Update, and the "Save" is where I am running into the exceptions.  Interestingly, the filename showing up in my FileNotFoundException is VisualStudioDebugPath\filename.xml

        public static FileInfo WriteToZipFile(IEnumerable<FileInfo> filesToZip, FileInfo zipFileInfo, bool moveToZip)
            if (!zipFileInfo.Directory.Exists)

            if (zipFileInfo.Exists && !ZipFile.IsZipFile(zipFileInfo.FullName))
                throw new Exception(String.Format("File '{0}' exists, but is not a Zip File.", zipFileInfo.FullName));

            using (ZipFile zipFile = (zipFileInfo.Exists) ? ZipFile.Read(zipFileInfo.FullName) : new ZipFile(zipFileInfo.FullName))
                zipFile.TempFileFolder = zipFileInfo.DirectoryName;
                foreach (FileInfo fileToZip in filesToZip)
                    if (fileToZip.Exists)
                        string zipPathEntryName = "";

                        if (fileToZip.DirectoryName != zipFileInfo.DirectoryName)
                            if (fileToZip.DirectoryName.Contains(zipFileInfo.DirectoryName))  // file is in a subdirectory of the zip file
                                zipPathEntryName = fileToZip.DirectoryName.Replace(zipFileInfo.DirectoryName, @".");
                            else if (fileToZip.Directory.Root != zipFileInfo.Directory.Root) // file is not even in the same root as the zip file
                                zipPathEntryName = fileToZip.DirectoryName.Replace(fileToZip.Directory.Root.Name, "");
                                DirectoryInfo zipFileDirectory = zipFileInfo.Directory;
                                bool matchFound = false;
                                string zipPathBackTrace = "";
                                while (!matchFound && zipFileDirectory != zipFileInfo.Directory.Root)
                                    zipFileDirectory = zipFileDirectory.Parent;
                                    zipPathBackTrace += @"..\";
                                    if (fileToZip.DirectoryName.Contains(zipFileDirectory.FullName))
                                        matchFound = true;

                                if (!matchFound)
                                    zipPathEntryName = zipPathBackTrace + fileToZip.DirectoryName.Remove(0, fileToZip.Directory.Root.Name.Length);
                                    zipPathEntryName = zipPathBackTrace + fileToZip.DirectoryName.Remove(0, zipFileDirectory.FullName.Length);
                            zipPathEntryName = fileToZip.DirectoryName;

                        if (zipFile.ContainsEntry(fileToZip.Name))
                            zipFile.UpdateFile(fileToZip.Name, zipPathEntryName);
                        else if (zipFile.ContainsEntry(fileToZip.FullName))
                            zipFile.UpdateFile(fileToZip.FullName, zipPathEntryName);
                            zipFile.AddFile(fileToZip.FullName, zipPathEntryName);


                        if (moveToZip)

            return new FileInfo(zipFileInfo.FullName);

Any insight would be appreciated.