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
(VB.NET) 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. Dim srcPath As String = "qa_data/hamlet.xml" Dim fs as System.IO.FileStream fs = File.OpenRead(srcPath) Dim sc As New Chilkat.StreamConnector Dim stream As 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 Dim success As Boolean = sc.SetAsSource(fs,stream) ' Set the stream's output (sink) to a file. Dim outPath As String = "qa_output/hamlet_copy_2.xml" stream.SinkFile = outPath ' Run the stream to copy from source to sink. success = stream.RunStream() If (success <> True) Then Debug.WriteLine(stream.LastErrorText) Exit Sub End If 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: Dim path3 As String = "qa_output/hamlet_copy_3.xml" Dim fsOut As 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) Then Debug.WriteLine(stream.LastErrorText) Exit Sub End If Debug.WriteLine("File successfully streamed to a System.IO.Stream.") |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.