Archive.Save

Save(Stream, ArchiveSaveOptions)

Saves archive to the stream provided.

public void Save(Stream outputStream, ArchiveSaveOptions saveOptions = null)
ParameterTypeDescription
outputStreamStreamDestination stream.
saveOptionsArchiveSaveOptionsOptions for archive saving.

Exceptions

exceptioncondition
ArgumentExceptionoutputStream is not writable.
ObjectDisposedExceptionArchive is disposed.

Remarks

outputStream must be writable.

Examples

using (FileStream zipFile = File.Open("archive.zip", FileMode.Create))
{
    using (var archive = new Archive())
    {
        archive.CreateEntry("entry.bin", "data.bin");
        archive.Save(zipFile);
    }
}

See Also


Save(string, ArchiveSaveOptions)

Saves archive to destination file provided.

public void Save(string destinationFileName, ArchiveSaveOptions saveOptions = null)
ParameterTypeDescription
destinationFileNameStringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
saveOptionsArchiveSaveOptionsOptions for archive saving.

Exceptions

exceptioncondition
ArgumentNullExceptiondestinationFileName is null.
SecurityExceptionThe caller does not have the required permission to access.
ArgumentExceptionThe destinationFileName is empty, contains only white spaces, or contains invalid characters.
UnauthorizedAccessExceptionAccess to file destinationFileName is denied.
PathTooLongExceptionThe specified destinationFileName, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
NotSupportedExceptionFile at destinationFileName contains a colon (:) in the middle of the string.
FileNotFoundExceptionThe file is not found.
DirectoryNotFoundExceptionThe specified path is invalid, such as being on an unmapped drive.
IOExceptionThe file is already open.

Remarks

It is possible to save an archive to the same path as it was loaded from. However, this is not recommended because this approach uses copying to temporary file.

Examples

using (var archive = new Archive())
{
    archive.CreateEntry("entry.bin", "data.bin");
    archive.Save("archive.zip",  new ArchiveSaveOptions() { Encoding = Encoding.ASCII });
}

See Also