i am trying to zip a list of files from a directory based on some criteria, using the selection property. Here is the code
using (ZipFile zip = new ZipFile())
{
string selection = "ctime > " + DateTime.Now.AddHours(-12).ToString("yyyy-MM-dd-HH:mm:ss");
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.AddSelectedFiles(selection, LogFolder, "", true);
if (zip.Entries.Count > 0)
{
zip.Name = ArchiveFile;
zip.Save();
}
}
As you can see, i am trying to archive the files created the last 12 hours in the Logfolder. Files get created in the logfolder all the time and they are deleted about 20 hours after their creation, so i try to archive them at the 12hour mark so that i dont lose files and so that files dont get deleted while i am trying to archive them. Yet i still get System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path '\core\e$\Program Files\Aspect Software\Unified IP\Logs\DBIServer\DBIServer[2013.11.05-12.41.11.263][569].log'.
As you can see, the file i am trying to archive was created on 2013-11-05 12:41 and the time that this code ran was more than 12h later. So why am i getting this exception? The file should not be going into the archive anyway! It's important to note that often the code runs fine and indeed does work properly archiving only the correct files. SO maybe the error has to do with the code looking through all the files in the folder even if its not gonna archive them? Any work around?
Thats the whole stacktrace: Message Executed as user: FCFS\fcdbadmin. ...ion 10.50.4000.0 for 64-bit Copyright (C) Microsoft Corporation 2010. All rights reserved. Started: 10:26:03 πμ Error: 2013-11-06 10:29:37.76 Code: 0x00000001 Source: DBIServer Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path '\core\e$\Program Files\Aspect Software\Unified IP\Logs\DBIServer\DBIServer[2013.11.05-12.41.11.263][569].log'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption) at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption) at System.IO.Directory.GetFiles(String path) at Ionic.Zip.ZipFile.AddOrUpdateDirectoryImpl(String directoryName, String rootDirectoryPathInArchive, AddOrUpdateAction action, Boolean recurse, Int32 level) at Ionic.Zip.ZipFile._AddOrUpdateSelectedFiles(String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, Boolean recurseDirectories, Boolean wantUpdate) at Ionic.Zip.ZipFile.AddSelectedFiles(String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, Boolean recurseDirectories) at ST_c13047ee91c340d78c1fbd7aa7c31ff9.csproj.ScriptMain.Main() --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() End Error Error: 2013-11-06 10:30:57.80 Code: 0x00000001 Source: CenterCord Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path '\core\e$\Program Files\Aspect Software\Unified IP\Logs\CenterCord\CenterCord-[2013.11.05-11.57.07.462][716].log'. at System.IO._Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption) at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption) at System.IO.Directory.GetFiles(String path) at Ionic.Zip.ZipFile.AddOrUpdateDirectoryImpl(String directoryName, String rootDirectoryPathInArchive, AddOrUpdateAction action, Boolean recurse, Int32 level) at Ionic.Zip.ZipFile._AddOrUpdateSelectedFiles(String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, Boolean recurseDirectories, Boolean wantUpdate) at Ionic.Zip.ZipFile.AddSelectedFiles(String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, Boolean recurseDirectories) at ST_c13047ee91c340d78c1fbd7aa7c31ff9.csproj.ScriptMain.Main() --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.R... The package execution fa... The step failed.
Turns out it was my bad afterall. In the SSIS package i had "CreateDeploymentUtility" set to False, so everytime i deployed the package, the changes did not actually go live on the server. Library works fine now.