Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C# Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
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)
MHT / HTML Email
MIME
MS Storage Providers
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
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C#) Using a .NET System.IO.Stream with Chilkat

Important: The Chilkat.StreamConnector class is not available in .NET Core or Mono. It is available only in the traditional Chilkat .NET assemblies.

The Chilkat.StreamConnector is a utility class to connect a System.IO.Stream to a Chilkat.Stream. Once connected, a .NET application can read or write a System.IO.Stream.

Here we have a trivial example showing how to connect a System.IO.Stream to a Chilkat.Stream.

Chilkat .NET Downloads

Chilkat .NET Framework

Chilkat for .NET Core

// First we'll demonstrate how to use a System.IO.FileStream as a source.
// Note: Any type of System.IO.Stream could be used, not just FileStream.

string srcPath = "qa_data/hamlet.xml";

System.IO.FileStream fs = File.OpenRead(srcPath);

Chilkat.StreamConnector sc = new Chilkat.StreamConnector();
Chilkat.Stream stream = new Chilkat.Stream();

// Set the System.IO.FileStream as the source for the Chilkat.Stream.
// When the Chilkat.Stream needs input, it will read from the System.IO.FileStream
bool success = sc.SetAsSource(fs,stream);

// Set the stream's output (sink) to a file.
string outPath = "qa_output/hamlet_copy_2.xml";
stream.SinkFile = outPath;

// Run the stream to copy from source to sink.
success = stream.RunStream();
if (success != true) {
    Debug.WriteLine(stream.LastErrorText);
    return;
}

Debug.WriteLine("File successfully streamed from a System.IO.Stream.");

// ----------------------------------------------------
// Now let's output to a System.IO.Stream

// Call Reset to make sure the Chilkat.Stream object has closed everything
// and is ready for something new..
stream.Reset();

// Clear the SinkFile property.  We'll be writing to a System.IO.Stream instead..
stream.SinkFile = "";

// Open a file for writing:
string path3 = "qa_output/hamlet_copy_3.xml";

System.IO.FileStream fsOut = File.OpenWrite(path3);

stream.SourceFile = srcPath;

// Set the fsOut to be the sink of the Chilkat.Stream
success = sc.SetAsSink(fsOut,stream);

// Run the stream.
// The file is copied from the source to the sink...
success = stream.RunStream();

// Make sure we close our System.IO.Stream

fsOut.Close();

if (success != true) {
    Debug.WriteLine(stream.LastErrorText);
    return;
}

Debug.WriteLine("File successfully streamed to a System.IO.Stream.");

 

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