{
  "WorkItem": {
    "AffectedComponent": {
      "Name": "",
      "DisplayName": ""
    },
    "ClosedComment": "I don&#39;t think this is a problem any longer.",
    "ClosedDate": "2009-09-13T23:39:17.923-07:00",
    "CommentCount": 0,
    "Custom": null,
    "Description": "Hi,\n \nI'm having trouble adding files to Zip in a ASP.Net web application. Running Vista, VS2008, Iconic.Zip.dll 1.8.4.16. I suspect it's something obvious that I'm missing.\n \n \n[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]\n   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0\n   System.Security.CodeAccessPermission.Demand() +58\n   System.IO.File.GetLastWriteTimeUtc(String path) +114\n   Ionic.Zip.ZipEntry.Create(String filename, String nameInArchive, Boolean isStream, Stream stream) +357\n   Ionic.Zip.ZipEntry.Create(String filename, String nameInArchive) +41\n   Ionic.Zip.ZipFile.AddFile(String fileName, String directoryPathInArchive) +68\n   eCommerce_DownloadDlinkInvoice.Page_Load(Object sender, EventArgs e) in C:\\Users\\Colin.DANKSNET\\Net\\Web\\Internet\\AxWeb\\Customer\\eCommerce\\DownloadDlinkInvoice.aspx.vb:47\n   System.Web.UI.Control.OnLoad(EventArgs e) +99\n   System.Web.UI.Control.LoadRecursive() +50\n   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785\n   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242\n   System.Web.UI.Page.ProcessRequest() +80\n   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21\n   System.Web.UI.Page.ProcessRequest(HttpContext context) +49\n   ASP.ecommerce_downloaddlinkinvoice_aspx.ProcessRequest(HttpContext context) +37\n   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181\n   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75",
    "LastUpdatedDate": "2013-05-16T05:32:12.403-07:00",
    "PlannedForRelease": "",
    "ReleaseVisibleToPublic": false,
    "Priority": {
      "Name": "Low",
      "Severity": 50,
      "Id": 1
    },
    "ProjectName": "DotNetZip",
    "ReportedDate": "2009-08-10T23:57:55.907-07:00",
    "Status": {
      "Name": "Closed",
      "Id": 4
    },
    "ReasonClosed": {
      "Name": "Unassigned"
    },
    "Summary": "Exception in File.GetLastWriteTimeUtc when adding file to Zip",
    "Type": {
      "Name": "Issue",
      "Id": 3
    },
    "VoteCount": 1,
    "Id": 8423
  },
  "FileAttachments": [
    {
      "FileId": 2208,
      "FileName": "DotNetZipLib-Runtime-v1.8.4.2300.zip",
      "DownloadUrl": ".\\2208"
    }
  ],
  "Comments": [
    {
      "Message": "Colin, try this build and see if it works for you. ",
      "PostedDate": "2009-08-11T00:07:34.677-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-08-11T00:07:37.457-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Hi Cheeso,\r\n\r\nIt moved the problem a bit further along. The exception now happens when the Zip.Save runs.\r\n\r\n==========================================================\r\n\r\n       'build the zip \r\n        Dim zip As New ZipFile\r\n        If Request.QueryString(\"f\") = \"All\" Then\r\n            'do explicit search for .inv files, if we use \"*.inv\" in getfiles() we also get \"*.inv_txf\" etc\r\n            Dim invFiles As New List(Of String)\r\n            Dim invfile As FileInfo\r\n            For Each invfile In diDlink.GetFiles()\r\n                'only add the inv files\r\n                If invfile.Extension = \".inv\" Then\r\n                    invFiles.Add(invfile.FullName)\r\n                End If\r\n            Next\r\n            'don't use the path of the source file in the Zip\r\n            zip.AddFiles(invFiles, \"\")\r\n        Else\r\n            'build a zip for a single file\r\n            Dim aaa As String = File.ReadAllText(dlinkDirectory & dlinkFile)\r\n            zip.AddFile(dlinkDirectory & dlinkFile, \"\")\r\n        End If\r\n\r\n        'download to customer\r\n        Response.ContentType = \"application/octet_stream\"\r\n        Response.AddHeader(\"content-disposition\", \"attachment; filename=\" & zipFilename)\r\n        zip.Save(Context.Response.OutputStream)\r\n\r\n==============================================================\r\nException Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.\r\n\r\nSource Error: \r\n\r\n\r\nLine 52:         Response.ContentType = \"application/octet_stream\"\r\nLine 53:         Response.AddHeader(\"content-disposition\", \"attachment; filename=\" & zipFilename)\r\nLine 54:         zip.Save(Context.Response.OutputStream)\r\n\r\n \r\n",
      "PostedDate": "2009-08-11T15:14:50.44-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Colin, it sure seems like you still don't have permissions to read the files that are being zipped up.  You didn't provide a stack trace, but I Would guess that's what it is.   Did you say you were running in full trust?  Regardless, I don't think trust of the assembly is the issue. IT is one of file permissions.  So the key thing is the USER ID or principal that the ASPNET page is running as.  That user needs to be able to read the files, and it seems like it can do lookups, can see that the files are there, but is not permitted to read the data from the files or read the timestamp.  I've never seen this. \r\nCan you provide a full stack trace? \r\nAnd also, can you check your permissions?   In the same code, can you do a File.Open() on the files in question?   I'm just guessing because I haven't seen the stack trace, but my guess is that this call is failing:  FileStream input = File.Open(LocalFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);  Can you do that in your code? \r\n\r\n\r\n",
      "PostedDate": "2009-08-12T13:08:09.813-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Hi Cheeso,\r\n\r\nI added the following code as per your suggestion -\r\n\r\n        Else\r\n            'build a zip for a single file\r\n            zip.AddFile(dlinkDirectory & dlinkFile, \"\")\r\n        End If\r\n\r\n        'download to customer\r\n        Response.ContentType = \"application/octet_stream\"\r\n        Response.AddHeader(\"content-disposition\", \"attachment; filename=\" & zipFilename)\r\n\r\n        Dim fs2 As FileStream = File.Open(dlinkDirectory & dlinkFile, FileMode.Open)\r\n        Dim readOk As Boolean = fs2.CanRead\r\n        Dim writeOk As Boolean = fs2.CanWrite\r\n        fs2.Close()\r\n\r\n        zip.Save(Context.Response.OutputStream)\r\n\r\nReadOK and WriteOK are both true when I step through with the debugger. The only place it fails is on the Zip.Save step???? Stack trace is below.\r\n\r\nLine 57:         fs2.Close()\r\nLine 58: \r\nLine 59:         zip.Save(Context.Response.OutputStream)\r\nLine 60: \r\nLine 61:         'rename all the inv files so we don't send again. This must be done after the zip.save or the save will fail.\r\n \r\n\r\nSource File: C:\\Users\\Colin.DANKSNET\\Net\\Web\\Internet\\AxWeb\\Customer\\eCommerce\\DownloadDlinkInvoice.aspx.vb    Line: 59 \r\n\r\nStack Trace: \r\n\r\n\r\n[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]\r\n   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0\r\n   System.Security.CodeAccessPermission.Demand() +58\r\n   System.IO.FileInfo..ctor(String fileName) +131\r\n   Ionic.Zip.ZipEntry.FigureCompressionMethodForWriting(Int32 cycle) +276\r\n   Ionic.Zip.ZipEntry.WriteHeader(Stream s, Int32 cycle) +1223\r\n   Ionic.Zip.ZipEntry.Write(Stream s) +119\r\n   Ionic.Zip.ZipFile.Save() +562\r\n   Ionic.Zip.ZipFile.Save(Stream outputStream) +163\r\n   eCommerce_DownloadDlinkInvoice.Page_Load(Object sender, EventArgs e) in C:\\Users\\Colin.DANKSNET\\Net\\Web\\Internet\\AxWeb\\Customer\\eCommerce\\DownloadDlinkInvoice.aspx.vb:59\r\n   System.Web.UI.Control.OnLoad(EventArgs e) +99\r\n   System.Web.UI.Control.LoadRecursive() +50\r\n   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785\r\n   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242\r\n   System.Web.UI.Page.ProcessRequest() +80\r\n   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21\r\n   System.Web.UI.Page.ProcessRequest(HttpContext context) +49\r\n   ASP.ecommerce_downloaddlinkinvoice_aspx.ProcessRequest(HttpContext context) +37\r\n   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181\r\n   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75\r\n\r\n================================\r\n\r\nI also tried to just send the file without zipping it (it's a text file), see below, which worked fine.\r\n\r\n        'download to customer\r\n        Response.ContentType = \"application/octet_stream\"\r\n        Response.AddHeader(\"content-disposition\", \"attachment; filename=\" & zipFilename)\r\n\r\n        Response.WriteFile(dlinkDirectory & dlinkFile)\r\n        '        zip.Save(Context.Response.OutputStream)\r\n\r\n\r\n \r\n",
      "PostedDate": "2009-08-12T20:15:13.41-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-08-25T11:54:42.933-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-08-25T11:54:43.927-07:00",
      "Id": -2147483648
    },
    {
      "Message": "colin, you still interested in solving this?  \r\nThe basic problem I think, is this:  I'm using FileInfo to get a bunch of information for the file in question.  Actually I need to get the length of the file; all the other information obtained for the file by the FileInfo class is not used.  But it is this other information in the fileinfo class that is causing the security Exception.  So I think I can avoid this problem by modifying the code to get the file length in some other way. \r\nAre you interested in testing if I provide another assembly for you? \r\n",
      "PostedDate": "2009-08-25T12:31:53.363-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Here's a new version with that change.  Please try it and let me know. ",
      "PostedDate": "2009-08-25T12:53:36.88-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-08-25T12:53:42.16-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Hi Cheeso,\r\nI'm happy to try out a new build. The emails you sent me didn't have it attached. Where can I pick it up from?\r\n\r\nRegards Colin...",
      "PostedDate": "2009-08-26T13:35:44.943-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Hey Colin\r\nactually I'm not sending emails to you directly.  \r\nI'm updating the workitem on the codeplex site. The emails are sent automatically.  \r\nUsually there is a link at the bottom of the generated email, saying something like \"view the full item here\".  \r\nIf not, you can download the version I built for you here:  http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=8423 \r\nThanks.",
      "PostedDate": "2009-08-26T20:21:02.017-07:00",
      "Id": -2147483648
    },
    {
      "Message": "any results?",
      "PostedDate": "2009-08-28T21:10:57.573-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Hi Cheeso,\r\nNot sure if I'm looking in the correct place. The latest attachement to the work item I can see is 1.4.8.2300 near the top. There are no comments etc for you or me after the \"Aug 11 at 5.07\" entry. I tried v1.4.8.2300, it has the same problem.\r\n\r\nRegards Colin...\r\n\r\n Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. \r\n\r\nException Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.\r\n\r\nSource Error: \r\n\r\n\r\nLine 53: \r\nLine 54:         Response.WriteFile(dlinkDirectory & dlinkFile)\r\nLine 55:         zip.Save(Context.Response.OutputStream)\r\nLine 56: \r\nLine 57:         'rename all the inv files so we don't send again. This must be done after the zip.save or the save will fail.\r\n \r\n\r\nSource File: C:\\Users\\Colin.DANKSNET\\Net\\Web\\Internet\\AxWeb\\Customer\\eCommerce\\DownloadDlinkInvoice.aspx.vb    Line: 55 \r\n\r\nStack Trace: \r\n\r\n\r\n[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]\r\n   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0\r\n   System.Security.CodeAccessPermission.Demand() +58\r\n   System.IO.FileInfo..ctor(String fileName) +131\r\n   Ionic.Zip.ZipEntry.FigureCompressionMethodForWriting(Int32 cycle) +137\r\n   Ionic.Zip.ZipEntry.WriteHeader(Stream s, Int32 cycle) +724\r\n   Ionic.Zip.ZipEntry.Write(Stream s) +64\r\n   Ionic.Zip.ZipFile.Save() +310\r\n   Ionic.Zip.ZipFile.Save(Stream outputStream) +76\r\n   eCommerce_DownloadDlinkInvoice.Page_Load(Object sender, EventArgs e) in C:\\Users\\Colin.DANKSNET\\Net\\Web\\Internet\\AxWeb\\Customer\\eCommerce\\DownloadDlinkInvoice.aspx.vb:55\r\n   System.Web.UI.Control.OnLoad(EventArgs e) +99\r\n   System.Web.UI.Control.LoadRecursive() +50\r\n   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785\r\n   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242\r\n   System.Web.UI.Page.ProcessRequest() +80\r\n   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21\r\n   System.Web.UI.Page.ProcessRequest(HttpContext context) +49\r\n   ASP.ecommerce_downloaddlinkinvoice_aspx.ProcessRequest(HttpContext context) +37\r\n   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181\r\n   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75\r\n\r\n \r\n\r\n",
      "PostedDate": "2009-08-30T13:39:38.707-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Colin - \r\n> Not sure if I'm looking in the correct place. The latest attachement to the work item I can see is 1.4.8.2300 near the top. There are no comments etc for you or me after the \"Aug 11 at 5.07\" entry. I tried v1.4.8.2300, it has the same problem.\r\n\r\nThe comments are in reverse order on the page.  The attachment you found is the correct one. \r\n\r\nBut, you haven't used the version I posted.  The exception stacktrace you gave cannot be produced by the DLL in that zip file. \r\n\r\nThe exception is being caused by the FileInfo class, and I removed that from the v1.8.4.2300 library.  No code calls the FileInfo() constructor in the version of the library attached to the workitem.  If you get a stacktrace that shows the FileInfo constructor, then you are using a different version of the DLL. Another way to check this is to call the static ZipFile.LibraryVersion method.  This will tell you which version of the library you're using.  You want 1.8.4.2300 . \r\n\r\nCan you please have another try, see if you can verify that you are using the 1.8.4.2300 library, and then see if it ebhaves any differently. ",
      "PostedDate": "2009-09-01T09:43:09.44-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Hi Cheeso,\r\n\r\nThanx for following this up, and sorry for being a pain. I was thrown by the orginal problem still being a the top. \r\n\r\nI have downloaded again and removed the reference from the project, checked that the dll was gone and added it again. The version in the bin folder is 1.8.4.2300. I added a line of code to check the version and got an error when checking the version! \r\n\r\nThe web application is running with an application pool that uses a domain user account as it has to access files on network shares and a remote SQL machine. Could this have something to do with it?\r\n\r\nSecurity Exception \r\nDescription: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. \r\n\r\nException Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.\r\n\r\nSource Error: \r\n\r\n\r\nLine 31:         'build the zip \r\nLine 32:         Dim zip As New ZipFile\r\nLine 33:         Dim version As String = ZipFile.LibraryVersion.ToString\r\nLine 34:         If Request.QueryString(\"f\") = \"All\" Then\r\nLine 35:             'do explicit search for .inv files, if we use \"*.inv\" in getfiles() we also get \"*.inv_txf\" etc\r\n \r\n\r\nSource File: C:\\Users\\Colin.DANKSNET\\Net\\Web\\Internet\\AxWeb\\Customer\\eCommerce\\DownloadDlinkInvoice.aspx.vb    Line: 33 \r\n\r\nStack Trace: \r\n\r\n\r\n[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]\r\n   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0\r\n   System.Security.CodeAccessPermission.Demand() +58\r\n   System.Reflection.Assembly.VerifyCodeBaseDiscovery(String codeBase) +118\r\n   System.Reflection.Assembly.GetName(Boolean copiedName) +70\r\n   System.Reflection.Assembly.GetName() +9\r\n   Ionic.Zip.ZipFile.get_LibraryVersion() +14\r\n   eCommerce_DownloadDlinkInvoice.Page_Load(Object sender, EventArgs e) in C:\\Users\\Colin.DANKSNET\\Net\\Web\\Internet\\AxWeb\\Customer\\eCommerce\\DownloadDlinkInvoice.aspx.vb:33\r\n   System.Web.UI.Control.OnLoad(EventArgs e) +99\r\n   System.Web.UI.Control.LoadRecursive() +50\r\n   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785\r\n   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242\r\n   System.Web.UI.Page.ProcessRequest() +80\r\n   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21\r\n   System.Web.UI.Page.ProcessRequest(HttpContext context) +49\r\n   ASP.ecommerce_downloaddlinkinvoice_aspx.ProcessRequest(HttpContext context) +37\r\n   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181\r\n   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75\r\n\r\n \r\n",
      "PostedDate": "2009-09-01T15:51:40.953-07:00",
      "Id": -2147483648
    },
    {
      "Message": "ok, well the LibraryVersion isn't the critical part. \r\n\r\nYou can skip that and check to see if what you originally wanted will now work. \r\n\r\nAs for your security issues, I don't know.  I'm not an expert in that stuff. \r\nIf DotNetZip doesn't do what you want, then I guess you need to do some more tests.  Maybe you can do some research and figure out what's restricted and what's not.  I don't know the policy that's required to run DotNetZip on your server.  Now you have a clear example of something that doesn't work:  getting the version number from a signed assembly.  Maybe you can write some test pages that don't use DotNetZip, and track this down.  \r\n\r\nOf course if the new library works for you, then you don't need to bother with this. \r\n",
      "PostedDate": "2009-09-01T17:35:46.947-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-09-13T23:39:17.923-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2013-02-21T18:44:05.78-08:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2013-05-16T05:32:12.403-07:00",
      "Id": -2147483648
    }
  ]
}