[
  {
    "Id": "566568",
    "ThreadId": "246139",
    "Html": "<p>I am using version 1.9.1.5 of Ionic.Zip. I have an SSIS 2008 script task, where an attempt is made to unzip one or more zip files in&nbsp;a specific directory out to the same directory. The problem I am having is that when the code runs, an exception is thrown that there are 'illegal characters in the path'. The zip files have the following naming convention: SmartExport_DW2001.02.01.zip. I have a feeling this is happening because I am not impelmenting the use of wildcards correctly. The following is my code in the script task:</p>\n<p>using System;<br />using System.Data;<br />using Ionic.Zip;<br />using Microsoft.SqlServer.Dts.Runtime;<br />using System.Windows.Forms;</p>\n<p>namespace ST_1cc80e7e0e4443f3815ad62038cbef3a.csproj<br />{<br />&nbsp;&nbsp;&nbsp; [System.AddIn.AddIn(\"ScriptMain\", Version = \"1.0\", Publisher = \"\", Description = \"\")]<br />&nbsp;&nbsp;&nbsp; public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase<br />&nbsp;&nbsp;&nbsp; {</p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region VSTA generated code<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enum ScriptResults<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion</p>\n<p><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void Main()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Variables vars = Dts.Variables;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String zipFile = vars[\"ZipFileProcessQueueLocationWildCard\"].Value.ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String unpackDirectory = vars[\"ZipFileProcessQueueLocation\"].Value.ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //String unpackDirectory = Dts.Variables[\"User::ZipFileProcessQueueLocation\"].Value.ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ZipFile zip = ZipFile.Read(zipFile);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (ZipEntry e in zip)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dts.TaskResult = (int)ScriptResults.Success;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}</p>\n<p>&nbsp;</p>\n<p>&nbsp;</p>\n<p>&nbsp;The package variable ZipFileProcessQueueLocationWildCard resolves to R:\\CasambaRefresh\\DWExport_ProcessQueue\\*.zip.&nbsp; The variable ZipFileProcessQueueLocation resolves to R:\\CasambaRefresh\\DWExport_ProcessQueue\\. The intent here is to unzip any file with a .zip extension in the directory.</p>\n<p>If I replace *.zip with a hard coded valid file name, the code works. That is, the end result is that the zip file is unzipped, and its contents are written to the correct location.</p>\n<p>What am I doing wrong?</p>\n<p>﻿The complete error message is as follows:</p>\n<p>﻿OnError,ORACLE,ADVOCAT_NT\\cdunn,Unzip,{C362B4AF-46D4-42EA-9DF5-23B65FD72C13},{86DA484C-03B2-4C72-ABC7-DF3CF8476FB6},2/15/2011 12:06:01 PM,2/15/2011 12:06:01 PM,1,0x,System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.ArgumentException: Illegal characters in path.<br />&nbsp;&nbsp; at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)<br />&nbsp;&nbsp; at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)<br />&nbsp;&nbsp; at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)<br />&nbsp;&nbsp; at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)<br />&nbsp;&nbsp; at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)<br />&nbsp;&nbsp; at Ionic.Zip.ZipFile.get_ReadStream()<br />&nbsp;&nbsp; at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)<br />&nbsp;&nbsp; at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)<br />&nbsp;&nbsp; at Ionic.Zip.ZipFile.Read(String fileName)<br />&nbsp;&nbsp; at ST_1cc80e7e0e4443f3815ad62038cbef3a.csproj.ScriptMain.Main()<br />&nbsp;&nbsp; --- End of inner exception stack trace ---<br />&nbsp;&nbsp; at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)<br />&nbsp;&nbsp; at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)<br />&nbsp;&nbsp; at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)<br />&nbsp;&nbsp; at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)<br />&nbsp;&nbsp; at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)<br />&nbsp;&nbsp; at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)<br />&nbsp;&nbsp; at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()<br />OnError,ORACLE,ADVOCAT_NT\\cdunn,CasambaRefresh_ProcessZipFiles,{DC446960-1FE8-43DE-A2C0-D88902ABACAC},{86DA484C-03B2-4C72-ABC7-DF3CF8476FB6},2/15/2011 12:06:01 PM,2/15/2011 12:06:01 PM,1,0x,System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.ArgumentException: Illegal characters in path.<br />&nbsp;&nbsp; at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)<br />&nbsp;&nbsp; at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)<br />&nbsp;&nbsp; at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)<br />&nbsp;&nbsp; at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)<br />&nbsp;&nbsp; at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)<br />&nbsp;&nbsp; at Ionic.Zip.ZipFile.get_ReadStream()<br />&nbsp;&nbsp; at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)<br />&nbsp;&nbsp; at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)<br />&nbsp;&nbsp; at Ionic.Zip.ZipFile.Read(String fileName)<br />&nbsp;&nbsp; at ST_1cc80e7e0e4443f3815ad62038cbef3a.csproj.ScriptMain.Main()<br />&nbsp;&nbsp; --- End of inner exception stack trace ---<br />&nbsp;&nbsp; at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)<br />&nbsp;&nbsp; at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)<br />&nbsp;&nbsp; at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)<br />&nbsp;&nbsp; at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)<br />&nbsp;&nbsp; at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)<br />&nbsp;&nbsp; at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)<br />&nbsp;&nbsp; at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()<br />OnTaskFailed,ORACLE,ADVOCAT_NT\\cdunn,Unzip,{C362B4AF-46D4-42EA-9DF5-23B65FD72C13},{86DA484C-03B2-4C72-ABC7-DF3CF8476FB6},2/15/2011 12:06:01 PM,2/15/2011 12:06:01 PM,0,0x,(null)<br />PackageEnd,ORACLE,ADVOCAT_NT\\cdunn,CasambaRefresh_ProcessZipFiles,{DC446960-1FE8-43DE-A2C0-D88902ABACAC},{86DA484C-03B2-4C72-ABC7-DF3CF8476FB6},2/15/2011 12:06:01 PM,2/15/2011 12:06:01 PM,1,0x,End of package execution.</p>\n<p>Thank you for your help!</p>\n<p>cdun2</p>",
    "PostedDate": "2011-02-15T09:03:05.74-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "566727",
    "ThreadId": "246139",
    "Html": "<p>Here's what you're doing wrong: the ZipFile constructor does not accept wildcards.</p>\r\n<p>You need to resolve that wildcard into an actual filename, and pass that filename into the ZipFile constructor.&nbsp; Do this with Directory.GetFiles().&nbsp; Also, you&nbsp;should use a using() clause.&nbsp; Always. Always. Always.&nbsp;The code looks like this:</p>\r\n<p><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Variables vars = Dts.Variables;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String wildcard = vars[<span style=\"color: #a31515;\">\"ZipFileProcessQueueLocationWildCard\"</span>].Value.ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String unpackDirectory = vars[<span style=\"color: #a31515;\">\"ZipFileProcessQueueLocation\"</span>].Value.ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">var</span> files = Directory.GetFiles(wildcard);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">if</span> (files!= <span style=\"color: blue;\">null</span> &amp;&amp; files.Length &gt;0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">string</span> zipFile = files[0];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">using</span> (ZipFile zip = ZipFile.Read(zipFile))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">foreach</span> (ZipEntry e <span style=\"color: blue;\">in</span> zip)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dts.TaskResult = (<span style=\"color: blue;\">int</span>)ScriptResults.Success;<br /><br />This resolves the wildcard, then extracts the first file in the list.&nbsp;&nbsp;In the general case, the wildcard will resolve into a list of more than one filename, and in that case you might want to modify the code to do a for loop around the using/extract loop.</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2011-02-15T13:21:04.97-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]