Exception when adding file to Zip

Aug 10, 2009 at 12:06 AM

Hi,

I'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.

The application is running with specific domain account for the application pool. The account has read/write access to the source files folder and c:\temp folder. I tried using the TempFileFolder="c:\temp" but have a simliar issue (complains it can't find the c:\temp folder) 

        'build the zip
        Dim zip As New ZipFile
        If Request.QueryString("f") = "All" Then
            'do explicit search for .inv files, if we use "*.inv" in getfiles() we also get "*.inv_txf" etc
            Dim invFiles As New List(Of String)
            Dim invfile As FileInfo
            For Each invfile In diDlink.GetFiles()
                'only add the inv files
                If invfile.Extension = ".inv" Then
                    invFiles.Add(invfile.FullName)
                End If
            Next
            'don't use the path of the source file in the Zip
            zip.AddFiles(invFiles, "")
        Else
            'build a zip for a single file
            zip.AddFile(dlinkDirectory & dlinkFile, "")
        End If

        'download to customer
        Response.ContentType = "application/octet_stream"
        Response.AddHeader("content-disposition", "attachment; filename=" & zipFilename)
        zip.Save(Context.Response.OutputStream)

Exception 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.

Source Error: 


Line 45:         Else
Line 46:             'build a zip for a single file
Line 47:             zip.AddFile(dlinkDirectory & dlinkFile, "")
Line 48:         End If
Line 49: 
 

Source File: C:\Users\Colin.DANKSNET\Net\Web\Internet\AxWeb\Customer\eCommerce\DownloadDlinkInvoice.aspx.vb    Line: 47 

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +58
   System.IO.File.GetLastWriteTimeUtc(String path) +114
   Ionic.Zip.ZipEntry.Create(String filename, String nameInArchive, Boolean isStream, Stream stream) +357
   Ionic.Zip.ZipEntry.Create(String filename, String nameInArchive) +41
   Ionic.Zip.ZipFile.AddFile(String fileName, String directoryPathInArchive) +68
   eCommerce_DownloadDlinkInvoice.Page_Load(Object sender, EventArgs e) in C:\Users\Colin.DANKSNET\Net\Web\Internet\AxWeb\Customer\eCommerce\DownloadDlinkInvoice.aspx.vb:47
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
   System.Web.UI.Page.ProcessRequest() +80
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.ecommerce_downloaddlinkinvoice_aspx.ProcessRequest(HttpContext context) +37
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

what am I missing?
Thanx Colin... 

 

Coordinator
Aug 10, 2009 at 6:42 AM

Colin, it seems like your ASPNET application is not able to READ the file being added to the ZIP.

Whatever  "dlinkDirectory & dlinkFile"  resolves to, is apparently not accessible to ASPNET.

The error you are seeing has nothing to do with ZipFile.TempFileFolder. ZipFile.TempFileFolder is a good thing to be aware of, when using DotNetZip from within ASPNET. But it isn't relevant when saving directly to a stream, which is what you are doing in this case.

-Cheeso

 

Aug 11, 2009 at 2:42 AM
Hi Cheeso,
I added a line of code (see below) to see if I could read the file into a string. This works OK, no errors. I can see the content of the file in the debugger, so it definetly opened and read the file OK. 
If I then step to the Zip.AddFile I still get the Security Exception. 
            'build a zip for a single file
            Dim aaa As String = File.ReadAllText(dlinkDirectory & dlinkFile)
            zip.AddFile(dlinkDirectory & dlinkFile, "")
Is it something to do with Trusting the ionic.zip.dll ? I have set full trust in my web.config file

Colin...
Coordinator
Aug 11, 2009 at 7:50 AM

No, I don't think it has to do with trusting Ionic.Zip.dll.  The app is failing when it tries to read the last write time of the file in question.  Is this a remote file? Is it on a share?

I don't know why DotNetZip is failing to read the LastWriteTime of the file.  But a failure there should not be critical.  I can modify the library so that it doesn't fail in this case - in other words it handles the exception.  But you'd have to test it yourself.

 

 

Coordinator
Aug 11, 2009 at 7:57 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Aug 11, 2009 at 8:07 AM

ok, try the build attached to the workitem:

http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=8423