Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C#) Using a .NET System.IO.Stream with ChilkatImportant: 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.
// 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.