filenotfoundexception if splitting archives with a particular folder

Feb 23, 2011 at 11:47 AM

 

 

If this directory is added : -

e:\Documents and Settings\whatever.WHAT\Desktop\scan pages -9

along with

zip.MaxOutputSegmentSize = 1024*1024 ;

Then I get this exception. if zip.MaxOutputSegmentSize = 1024*1024 ; is removed . then everything works. Similarly if the above mentioned directory is not added to the zipfile. the then things work. I have no idea why this happens.

I am using the using clause.

The exception :

System.IO.FileNotFoundException was unhandled
Message="Could not find file 'C:\\MyZipFile.z01'."
Source="mscorlib"
FileName="C:\\MyZipFile.z01"


StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at Ionic.Zip.ZipSegmentedStream.TruncateBackward(UInt32 diskNumber, Int64 offset)


at Ionic.Zip.ZipEntry.Write(Stream s)
at Ionic.Zip.ZipFile.Save()
at Ionic.Zip.ZipFile.Save(String fileName)
at WindowsFormsApplication1.Form1.backup_to_folder(String folderToSave) in E:\My Downloads\Visual Studio 2008\Projects\Backup\Backup\Backup-to-Gmail.cs:line 289
at WindowsFormsApplication1.Form1.run_zip_thread(String folderToSave, Object sender) in E:\My Downloads\Visual Studio 2008\Projects\Backup\Backup\Backup-to-Gmail.cs:line 161
at WindowsFormsApplication1.Form1.<>c__DisplayClass1.<button3_Click>b__0() in E:\My Downloads\Visual Studio 2008\Projects\Backup\Backup\Backup-to-Gmail.cs:line 152
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

 

My code:

using (ZipFile zip = new ZipFile())
{

zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level9;

if (textBox2.Text != "")
{

zip.Encryption = EncryptionAlgorithm.WinZipAes256;
zip.Password = textBox2.Text;
}

foreach (string s in addlist)
{
// add this map file into the "images" directory in the zip archive
if (File.Exists(s))
{
//try
{
Console.WriteLine("adding file");
zip.AddFile(s);

}
//// catch (ArgumentException ae)
//{
// Console.WriteLine("duplicate detected");
//}
// MessageBox.Show("addedfile");
}

else if (Directory.Exists(s))
{

string[] allfiles = Directory.GetFiles(s, "*.*", SearchOption.AllDirectories);
string[] alldirs = Directory.GetDirectories(s, "*", SearchOption.AllDirectories);




foreach (string s2 in allfiles)
{
include = true ;
foreach (string ex in excludelist)
{
if (s2.Contains(ex) && ex != "" )
{
include = false;
// Console.WriteLine("include=false. s2=" + s2 + ". ex=" + ex ) ;
break ;
}
}

if ( include == true )
{
// try
{
zip.AddFile(s2);
}
// catch (ArgumentException ae)
{

}
}
}

foreach (string s3 in alldirs)
{
include = true;
foreach (string ex in excludelist)
{
if ( (s3.Contains(ex) && ex != "") || !dirempty(s3))
{
include = false;
// Console.WriteLine("include=false. s3=" + s3 + ". ex=" + ex);
break;
}
}

if (include == true)
{
//try
{
zip.AddDirectory(s3, new DirectoryInfo(s3).FullName);
}
// catch (ArgumentException ae)
{

}
}
}


}

else
{
// MessageBox.Show("error");
// path doesn't exist.

}
}

//try
{
zip.MaxOutputSegmentSize = 1024*1024 ;
zip.Save( folderToSave + "\\" + "MyZipFile.zip");

}
// catch (IOException ioe)
//{
// MessageBox.Show("Could not add one of the files/folders :( " + ioe.Data);
// }
//catch(FileNotFoundException de )
//{
// Console.WriteLine("ignore") ;
// MessageBox.Show("Problem");
//}

pictureBox1.Image = null;
MessageBox.Show("zipped!");
}

This forum is all broken in opera btw

Feb 24, 2011 at 9:22 AM

I have narrowed down the problem. The problem is not with the directory, but with the following file:  http://dillibuy.x10.bz/temp/scan%20pages.zip

If this file is included along with   zip.MaxOutputSegmentSize = 200 * 1024; .

Then the following exception is thrown

System.IO.FileNotFoundException was unhandled
Message="Could not find file 'e:\\Documents and Settings\\whatever.WHAT\\Local Settings\\Temp\\uytxcabjv\\NoFrillsBackup 2011-02-24 14;46.z01'."


Source="mscorlib"
FileName="e:\\Documents and Settings\\whatever.WHAT\\Local Settings\\Temp\\uytxcabjv\\NoFrillsBackup 2011-02-24 14;46.z01"


StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at Ionic.Zip.ZipSegmentedStream.TruncateBackward(UInt32 diskNumber, Int64 offset)
at Ionic.Zip.ZipEntry.Write(Stream s)
at Ionic.Zip.ZipFile.Save()
at Ionic.Zip.ZipFile.Save(String fileName)
at WindowsFormsApplication1.Form1.backup_to_folder(String folderToSave, Object sender) in E:\My Downloads\Visual Studio 2008\Projects\Backup\Backup\Backup-to-Gmail.cs:line 351
at WindowsFormsApplication1.Form1.run_zip_thread(String folderToSave, Object sender) in E:\My Downloads\Visual Studio 2008\Projects\Backup\Backup\Backup-to-Gmail.cs:line 186
at WindowsFormsApplication1.Form1.<>c__DisplayClass4.<button7_Click>b__3() in E:\My Downloads\Visual Studio 2008\Projects\Backup\Backup\Backup-to-Gmail.cs:line 529
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 InnerException:

 

Please help!