Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaJavaScriptNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C# Examples
Web API Categories

AI
ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Apple Keychain
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
JavaScript
MHT / HTML Email
MIME
Markdown
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C#) ZIP a Visual Studio Project and Exclude Build Artifacts

See more Zip Examples

This example demonstrates how to create a ZIP archive of a Visual Studio project directory while excluding files and directories commonly created during builds.

This is useful when archiving or sharing source code without including compiled binaries, intermediate build output, debug symbols, cache files, or generated package folders.

The example excludes common Visual Studio build artifacts such as:

  • bin directories
  • obj directories
  • .vs directories
  • *.exe, *.dll, *.pdb, and related output files
  • Temporary and cache files

Chilkat .NET Downloads

Chilkat .NET Framework

Chilkat for .NET Core

bool success = false;

Chilkat.Zip zip = new Chilkat.Zip();

// Create a new, empty Zip object.
// The .zip file is not created until WriteZip or WriteZipAndClose is called.
success = zip.NewZip("VisualStudioProject.zip");
if (success == false) {
    Debug.WriteLine(zip.LastErrorText);
    return;
}

// When the ZIP is extracted, all files will be placed beneath
// the "MyProject/" directory.
// 
// For example:
// 
//     src/main.cpp
// 
// Will be stored in the ZIP as:
// 
//     MyProject/src/main.cpp
// 
zip.PathPrefix = "MyProject/";

// We will add files from this Visual Studio project directory:
// 
//     c:/projects/MyProject
// 
// The goal is to ZIP the source project without the files generated
// by Visual Studio builds.

// ------------------------------------------------------------
// Exclude directories commonly created by Visual Studio builds.
// 
// Any directory having one of these names will be skipped entirely,
// including all files and subdirectories beneath it.
zip.ExcludeDir("bin");
zip.ExcludeDir("obj");
zip.ExcludeDir(".vs");
zip.ExcludeDir("packages");

// ------------------------------------------------------------
// Create a StringArray containing wildcard exclusion patterns
// for generated files and temporary artifacts.
Chilkat.StringArray saExcludes = new Chilkat.StringArray();

// Exclude common compiled output files.
saExcludes.Append("*.exe");
saExcludes.Append("*.dll");
saExcludes.Append("*.pdb");
saExcludes.Append("*.ilk");
saExcludes.Append("*.lib");
saExcludes.Append("*.obj");

// Exclude NuGet package files.
saExcludes.Append("*.nupkg");

// Exclude temporary, cache, and user-specific files.
saExcludes.Append("*.cache");
saExcludes.Append("*.tmp");
saExcludes.Append("*.user");
saExcludes.Append("*.suo");
saExcludes.Append("*.log");

// Apply the wildcard exclusion patterns to the Zip object.
zip.SetExclusions(saExcludes);

// ------------------------------------------------------------
// Recursively add references to the project files.
// 
// AppendFiles does not immediately read or compress the files.
// It adds file references to the Zip object. The referenced files
// are read and compressed later when WriteZipAndClose is called.
bool recurse = true;

success = zip.AppendFiles("c:/projects/MyProject/*",recurse);
if (success == false) {
    Debug.WriteLine(zip.LastErrorText);
    return;
}

// ------------------------------------------------------------
// Write the ZIP archive and close it.
// 
// This is where the referenced source files are actually read,
// compressed as needed, and written to the final .zip archive.
success = zip.WriteZipAndClose();
if (success == false) {
    Debug.WriteLine(zip.LastErrorText);
    return;
}

Debug.WriteLine("Visual Studio project ZIP created successfully.");

 

© 2000-2026 Chilkat Software, Inc. All Rights Reserved.