Xceed .NET Libraries Documentation
Xceed.Zip Assembly / Xceed.Zip Namespace / ZipArchive Class / DefaultPasswordTextEncoding Property


DefaultPasswordTextEncoding Property (ZipArchive)

Gets or sets a value that indicates the text encoding to use when processing passwords.

Syntax
'Declaration
 
Public Property DefaultPasswordTextEncoding As Encoding
 
'Usage
 
Dim instance As ZipArchive
Dim value As Encoding
 
instance.DefaultPasswordTextEncoding = value
 
value = instance.DefaultPasswordTextEncoding

Property Value

A Encoding object that represents the text encoding to use when processing passwords. By default, the value is a null reference (Nothing in Visual Basic).
Remarks
There is no accepted standard on how to encode non-ASCII characters in passwords. That means every zip tool/library can end up doing it differently. This is why it is strongly recommended to use ASCII characters only in passwords if compatibility is important as it's the only "standard" that all zip tools will honor.

If Xceed Zip components are the only tools used, non-ASCII passwords, there won't be an issue. But if the resulting zip file will be shared with another zip tool/library or vice-versa, it won't work because Xceed might encode passwords differently than other tools.
Example
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 );
    }

  }
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also