Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

C# Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
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
NTLM
OAuth1
OAuth2
Office365
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(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 Assemblies

Chilkat for .NET Core

Chilkat for Mono

// 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-2020 Chilkat Software, Inc. All Rights Reserved.