- fileName (String)
- The name of the file to add. It should refer to a file in the filesystem. The name of the file may be a relative path or a fully-qualified path.
This call collects metadata for the named file in the filesystem, including the file attributes and the timestamp, and inserts that metadata into the resulting ZipEntry. Only when the application calls Save() on the ZipFile, does DotNetZip read the file from the filesystem and then write the content to the zip file archive.
This method will throw an exception if an entry with the same name already exists in the ZipFile.
For ZipFile properties including Encryption, Password, SetCompression, ProvisionalAlternateEncoding, ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.
In this example, three files are added to a Zip archive. The ReadMe.txt file will be placed in the root of the archive. The .png file will be placed in a folder within the zip called photos\personal. The pdf file will be included into a folder within the zip called Desktop.
try { using (ZipFile zip = new ZipFile()) { zip.AddFile("c:\\photos\\personal\\7440-N49th.png"); zip.AddFile("c:\\Desktop\\2008-Regional-Sales-Report.pdf"); zip.AddFile("ReadMe.txt"); zip.Save("Package.zip"); } } catch (System.Exception ex1) { System.Console.Error.WriteLine("exception: " + ex1); }
Try Using zip As ZipFile = New ZipFile zip.AddFile("c:\photos\personal\7440-N49th.png") zip.AddFile("c:\Desktop\2008-Regional-Sales-Report.pdf") zip.AddFile("ReadMe.txt") zip.Save("Package.zip") End Using Catch ex1 As Exception Console.Error.WriteLine("exception: {0}", ex1.ToString) End Try