Network AddFile problem

Oct 6, 2008 at 7:32 PM
Edited Oct 6, 2008 at 7:33 PM
Thanks for this potentially fantastic library.
However I'm having problems getting it to work in my situation.
In my VB ASP.NET project I'm trying to zip up a binary file and attach to an email, send the zip then delete the zip.
1. When the e-mail arrives, the attached ZIP file is empty, it's like the ZIP file can't add a network file to the zip file on the network.
2. When I try and delete the ZIP file at the end, it's still locked. I can't see a 'Close' function to unlock it, only Dispose, which doesn't unlock it.
Thanks for any help you can provide.
Will.

Here's a portion of the code:

 

Dim zip As New ZipFile("\\server1\ftproot\Licence\Engineer\1002.zip")
zip.AddFile("\\server1\ftproot\Licence\Engineer\1002.inf")
zip.Save()

Dim mail As New System.Net.Mail.MailMessage
Dim attachment As New System.Net.Mail.Attachment("\\server1\ftproot\Licence\Engineer\1002.zip")
mail.Attachments.Add(attachment)

Dim
mClient As New System.Net.Mail.SmtpClient
mClient.Host =
"ourEMailServer"
mClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials()
mClient.Send(mail)

If File.Exists("\\server1\ftproot\Licence\Engineer\1002.zip") Then
    File.Delete("\\server1\ftproot\Licence\Engineer\1002.zip")
End If

 

Coordinator
Oct 7, 2008 at 1:09 AM

Hmm, I don't know what the problem is, but can you please wrap your use of the ZipFile in a using clause, eg:

        Dim ZipToCreate As String = "\\server1\ftproot\whatever.zip"

        If File.Exists(ZipToCreate) Then
            'Console.WriteLine("Deletting existing zip file: {0}", ZipToCreate)
            File.Delete(ZipToCreate)
        End If

        'Console.WriteLine("Creating new zip file: {0}", ZipToCreate)

        Using zip As ZipFile = New ZipFile(ZipToCreate)
          zip.AddFile("\\server1\ftproot\whatever\you\like.txt") 
          zip.Save()
        End Using

        ' at this point the zip file should exist, and should be readable.