Error Extracting PDF File from a ZIP mail attachment

Jul 22, 2011 at 6:10 PM

I am working on a web page which creates a .PDF file dynamically using CETE Dynamic  PDF.  This is saved in a memory stream.  I then save that file as a .zip using DotNetZip in a memory stream.  The resultant zip file is used as an attachment for an Outlook email message.   The problem comes when trying to extract the .zip file in the Outlook email message.  I get the following error:

An unexpected error is keep you from copying the file.  ... Error 0x80070057: the parameter is incorrect.  

If I then press the "Try Again" button, I get a message about copying the file.  "There is already a file with the same name in this location."  I may "copy and replace", "don't copy "or "copy but keep both files."  The only choice that doesn't get another message is to not copy.  I don't know why it is trying to copy and how to avoid the message.

This is the code I am using:
   'put the PDF file into a .zip format
 Using zip As ZipFile = New ZipFile
     zip.AddEntry(sFileName, oStreamFinal)
     zip.ZipErrorAction = ZipErrorAction.Skip
 End Using

 ' move the stream position to the beginning
 oZipStream.Seek(0, SeekOrigin.Begin)

 'Quote with any merged documents
 oAttachment(0) = New System.Net.Mail.Attachment(oZipStream, sZipFileName)



Jul 23, 2011 at 2:51 PM
Edited Jul 25, 2011 at 6:33 PM

based on a quick look, this is not a DotNetZip problem. It seems to me that you are using the System.Net.Mail.Attachment class incorrectly. See the doc page at . The constructor that accepts a stream and a string - the constructor you are using - wants the string to be the Content Type, not the filename. If you want to specify the filename with a stream, then you need to System.Net.Mail.Attachment differently. 

dim ct As New ContentType()
' specify the media type for Zip files...
ct.MediaType = MediaTypeNames.Application.Zip 
ct.Name = "something-" & DateTime.Now.ToString() & ".zip"
' Create the attachment.
dim att As New Attachment(oZipStream, ct)


If that is not the problem, then I don't know.  I don't know about Outlook and email attachments.  I don't know about "copy"  "copy and replace" or "copy but keep both".  I don't know what that is and I cannot help you with that.

I can help with the zip part.  What I suggest for diagnosing this problem is to first isolate the problem.  Separate the "zip generation" from the "email generation".  In the zip generation part, save the generated zip file to a filesystem file.  See if you can correctly read and extract the generated zip file, see if the PDF you extract matches what you expect.  If it does, then you know the zip generation is correct. 

After determining that the zip generation works properly, add in the Outlook / attachment piece.


Jul 25, 2011 at 4:19 PM

That worked.  Thanks so much for your help!