Adds a single file to current zip file.
[Visual Basic]
Public Sub AddFile( _
fileName As String, _
alternativeName As String, _
password As String _
)
Public Sub AddFile( _
fileName As String, _
s As Stream, _
password As String, _
attrs As FileAttributes, _
dt As System.DateTime _
)
Public Sub AddFile( _
fileName As String, _
data() As Byte, _
password As String, _
attrs As FileAttributes, _
dt As System.DateTime _
)
[C#]
public void AddFile(
string fileName,
string alternativeName,
string password
);
public void AddFile(
string fileName,
Stream s,
string password,
FileAttributes attrs,
System.DateTime dt
);
public void AddFile(
string fileName,
byte[] data,
string password,
FileAttributes attrs,
System.DateTime dt
);
[C++]
public: void AddFile(
String* fileName,
String* alternativeName,
String* password
);
public: void AddFile(
String* fileName,
Stream* s,
String* password,
FileAttributes attrs,
System::DateTime dt
);
public: void AddFile(
String* fileName,
unsigned char data __gc[],
String* password,
FileAttributes attrs,
System::DateTime dt
);
[JScript]
public function AddFile(
fileName: String,
alternativeName: String,
password: String
);
public function AddFile(
fileName: String,
s: Stream,
password: String,
attrs: FileAttributes,
dt: DateTime
);
public function AddFile(
fileName: String,
data: Byte[],
password: String,
attrs: FileAttributes,
dt: DateTime
);
Parameters
Example
[Visual Basic, C#, C++] The following example demonstrates how to compress/decompress file with EACompression Zip Component. This sample doesn't demonstrates the events, please refer to Samples section to get the full samples of EACompression.
[Visual Basic]
Imports EACompression
Imports System.IO
Sub Zip()
Try
Dim oZip As New ZipArchive("TryIt")
oZip.Create("c:\test.zip", True) 'create a new zip file
Dim password As String = ""
'add a single file to zip file.
oZip.AddFile("c:\test.gif", "", password)
'add a single file by stream
'Dim fs As New FileStream("c:\test.gif", FileMode.Open)
'oZip.AddFile("test.gif", fs, password, FileAttributes.Archive, System.DateTime.Now)
'fs.Close()
'add a single file by binary data
'Dim fss As New FileStream("c:\test.gif", FileMode.Open)
'Dim data(fss.Length - 1) As Byte
'fss.Read(data, 0, fss.Length)
'fss.Close()
'oZip.AddFile("test.gif", data, password, FileAttributes.Archive, System.DateTime.Now)
Catch ep As Exception
Console.Write(ep.Message)
End Try
End Sub
[C#]
using System;
using System.Collections;
using EACompression;
using System.IO;
void Zip()
{
try
{
ZipArchive oZip = new ZipArchive( "TryIt" );
oZip.Create( "c:\\test.zip", true ); //create a new zip file;
string password = "";
//add a single file to zip file.
oZip.AddFile( "c:\\test.gif", "", password );
//add a single file by stream
//FileStream fs = new FileStream( "c:\\test.gif", FileMode.Open );
//oZip.AddFile( "test.gif", fs, password, FileAttributes.Archive, System.DateTime.Now );
//fs.Close();
//add a single file by binary data
//FileStream fss = new FileStream( "c:\\test.gif", FileMode.Open );
//byte[] data = new byte[fss.Length];
//fss.Read( data, 0, (int)fss.Length );
//fss.Close();
//oZip.AddFile( "test.gif", data, password, FileAttributes.Archive, System.DateTime.Now );
}
catch( Exception ep )
{
Console.Write( ep.Message );
}
}
[C++]
using namespace System;
using namespace System::Collections;
using namespace System::IO;
using namespace EACompression;
void Zip()
{
try
{
ZipArchive *oZip = new ZipArchive( S"TryIt" );
oZip->Create( S"c:\\test.zip", true ); //create a zip file;
String *password = S"";
//add a single file to zip file.
oZip->AddFile( S"c:\\test.gif", S"", password );
//add a single file by stream
//FileStream *fs = new FileStream( S"c:\\test.gif", FileMode::Open );
//oZip->AddFile( S"test.gif", fs, password, FileAttributes::Archive, System::DateTime::Now );
//fs->Close();
//add a single file by binary data
//FileStream *fss = new FileStream( S"c:\\test.gif", FileMode::Open );
//unsigned char data __gc[] = new unsigned char __gc[fss->Length];
//fss->Read( data, 0, (int)fss->Length );
//fss->Close();
//oZip->AddFile( S"test.gif", data, password, FileAttributes::Archive, System::DateTime::Now );
}
catch( Exception *ep )
{
Console::Write( ep->Message );
}
}