using System;
using Xceed.FileSystem;
using Xceed.Zip;
namespace DocumentationExamples.Zip
{
class DefaultPasswordTextEncodingProperty
{
static void DefaultPasswordTextEncodingExample()
{
string password = "kf/E@´d!i_p7/ow`TgK!SV1w65X<y#";
// Setup a text encoding object that mimics the password encoding performed by 7-Zip
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding( 1252, new System.Text.EncoderExceptionFallback(), new System.Text.DecoderReplacementFallback( "_" ) );
AbstractFolder baseFolder = new DiskFolder( @"D:\DocumentationExamples.Zip" );
AbstractFile zipFile = baseFolder.GetFile( "DefaultPasswordTextEncodingExample.zip" );
if( zipFile.Exists ) zipFile.Delete();
ZipArchive zip = new ZipArchive( zipFile );
zip.DefaultEncryptionMethod = EncryptionMethod.WinZipAes;
zip.DefaultEncryptionPassword = password;
zip.DefaultDecryptionPassword = password;
// Make the archive use our own text encoding for the password
zip.DefaultPasswordTextEncoding = encoding;
using( new AutoBatchUpdate( zip ) )
{
AbstractFile file = new DiskFile( @"D:\SomeFile.dat" );
file.CopyTo( zip, true );
}
AbstractFolder folder = baseFolder.GetFolder( "Output" );
zip.CopyFilesTo( folder, true, true );
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports Xceed.FileSystem
Imports Xceed.Zip
Namespace DocumentationExamples.Zip
Friend Class DefaultPasswordTextEncodingProperty
Private Shared Sub DefaultPasswordTextEncodingExample()
Dim password As String = "kf/E@�d!i_p7/ow`TgK!SV1w65X<y#"
' Setup a text encoding object that mimics the password encoding performed by 7-Zip
Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(1252, New System.Text.EncoderExceptionFallback(), New System.Text.DecoderReplacementFallback("_"))
Dim baseFolder As AbstractFolder = New DiskFolder("D:\DocumentationExamples.Zip")
Dim zipFile As AbstractFile = baseFolder.GetFile("DefaultPasswordTextEncodingExample.zip")
If zipFile.Exists Then
zipFile.Delete()
End If
Dim zip As New ZipArchive(zipFile)
zip.DefaultEncryptionMethod = EncryptionMethod.WinZipAes
zip.DefaultEncryptionPassword = password
zip.DefaultDecryptionPassword = password
' Make the archive use our own text encoding for the password
zip.DefaultPasswordTextEncoding = encoding
Using TempAutoBatchUpdate As AutoBatchUpdate = New AutoBatchUpdate(zip)
Dim file As AbstractFile = New DiskFile("D:\SomeFile.dat")
file.CopyTo(zip, True)
End Using
Dim folder As AbstractFolder = baseFolder.GetFolder("Output")
zip.CopyFilesTo(folder, True, True)
End Sub
End Class
End Namespace