Zip files
-
I am generating a zip file and then emailing it. I am using a temp directory to create this file but i will always be creating a number of different files using this directory. The problem i am having is when i go to delete the files inside my temp directory i get an error saying that the zip file is being used by another process. I have stepped through the code and waited until the email was sent to be sure that its not being locked there. I have also set the zipfile to null and that still didnt work. if anyone has any ideas as to what might be causing this i would be forever grateful.
if (!CreatedTempFolder) { //if not dir exists if (!System.IO.Directory.Exists(TempFileLocation)) // create it System.IO.Directory.CreateDirectory(TempFileLocation); else { //delete all files from temp foleder System.IO.Directory.Delete(TempFileLocation, true); System.IO.Directory.CreateDirectory(TempFileLocation); } //set CreatedTempFolder to true string zipFileName = string.Format("{0}\\\\{1}.zip", TempFileLocation, DrSched\["GROUPNAME"\].ToString()); MyZip zipfile = new MyZip(zipFileName,"W"); foreach (string fileName in System.IO.Directory.GetFiles(TempFileLocation,"\*.csv")) zipfile.AddFile(fileName); //zipfile.Save(); zipfile.Close(); zipfile = null; GC.Collect();
-
I am generating a zip file and then emailing it. I am using a temp directory to create this file but i will always be creating a number of different files using this directory. The problem i am having is when i go to delete the files inside my temp directory i get an error saying that the zip file is being used by another process. I have stepped through the code and waited until the email was sent to be sure that its not being locked there. I have also set the zipfile to null and that still didnt work. if anyone has any ideas as to what might be causing this i would be forever grateful.
if (!CreatedTempFolder) { //if not dir exists if (!System.IO.Directory.Exists(TempFileLocation)) // create it System.IO.Directory.CreateDirectory(TempFileLocation); else { //delete all files from temp foleder System.IO.Directory.Delete(TempFileLocation, true); System.IO.Directory.CreateDirectory(TempFileLocation); } //set CreatedTempFolder to true string zipFileName = string.Format("{0}\\\\{1}.zip", TempFileLocation, DrSched\["GROUPNAME"\].ToString()); MyZip zipfile = new MyZip(zipFileName,"W"); foreach (string fileName in System.IO.Directory.GetFiles(TempFileLocation,"\*.csv")) zipfile.AddFile(fileName); //zipfile.Save(); zipfile.Close(); zipfile = null; GC.Collect();
-
I am generating a zip file and then emailing it. I am using a temp directory to create this file but i will always be creating a number of different files using this directory. The problem i am having is when i go to delete the files inside my temp directory i get an error saying that the zip file is being used by another process. I have stepped through the code and waited until the email was sent to be sure that its not being locked there. I have also set the zipfile to null and that still didnt work. if anyone has any ideas as to what might be causing this i would be forever grateful.
if (!CreatedTempFolder) { //if not dir exists if (!System.IO.Directory.Exists(TempFileLocation)) // create it System.IO.Directory.CreateDirectory(TempFileLocation); else { //delete all files from temp foleder System.IO.Directory.Delete(TempFileLocation, true); System.IO.Directory.CreateDirectory(TempFileLocation); } //set CreatedTempFolder to true string zipFileName = string.Format("{0}\\\\{1}.zip", TempFileLocation, DrSched\["GROUPNAME"\].ToString()); MyZip zipfile = new MyZip(zipFileName,"W"); foreach (string fileName in System.IO.Directory.GetFiles(TempFileLocation,"\*.csv")) zipfile.AddFile(fileName); //zipfile.Save(); zipfile.Close(); zipfile = null; GC.Collect();
You haven't stated what zipFile is (build in .Net functionality? sharpZipLib? Other third party?) however I suspect the problem is you need to call
Dispose
as well asClose
, so that it releases unmanaged resources, in this case the underlying file.If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
You haven't stated what zipFile is (build in .Net functionality? sharpZipLib? Other third party?) however I suspect the problem is you need to call
Dispose
as well asClose
, so that it releases unmanaged resources, in this case the underlying file.If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
Thanks for your help i have found a work around from this i am still not 100% sure exactly what MyZip(its company specific). Thanks for all your help !!! Dino
-
I am generating a zip file and then emailing it. I am using a temp directory to create this file but i will always be creating a number of different files using this directory. The problem i am having is when i go to delete the files inside my temp directory i get an error saying that the zip file is being used by another process. I have stepped through the code and waited until the email was sent to be sure that its not being locked there. I have also set the zipfile to null and that still didnt work. if anyone has any ideas as to what might be causing this i would be forever grateful.
if (!CreatedTempFolder) { //if not dir exists if (!System.IO.Directory.Exists(TempFileLocation)) // create it System.IO.Directory.CreateDirectory(TempFileLocation); else { //delete all files from temp foleder System.IO.Directory.Delete(TempFileLocation, true); System.IO.Directory.CreateDirectory(TempFileLocation); } //set CreatedTempFolder to true string zipFileName = string.Format("{0}\\\\{1}.zip", TempFileLocation, DrSched\["GROUPNAME"\].ToString()); MyZip zipfile = new MyZip(zipFileName,"W"); foreach (string fileName in System.IO.Directory.GetFiles(TempFileLocation,"\*.csv")) zipfile.AddFile(fileName); //zipfile.Save(); zipfile.Close(); zipfile = null; GC.Collect();