GetStream |
Scroll |
Get a reference to the IStream object representing the file stream.
Namespace: Therefore.API
Parameters nStreamNo The 0-based index of the stream.
Return Value The document number of the new document. |
|
C# Sample
//retrieve document with docno 12345
TheDocument theDoc = new TheDocument();
theDoc.Retrieve(12345, "", server);
System.Runtime.InteropServices.ComTypes.IStream theStream = (System.Runtime.InteropServices.ComTypes.IStream)theDoc.GetStream(0); //get first stream
Stream outStream = new MemoryStream(); //output
int cb = 4096; //block size
byte[] buffer = new byte[cb]; //buffer in block size
int read = 0; //read bytes
do
{
 IntPtr bytesRead = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(int))); //get COM memory for saving read bytes
 try
 {
 theStream.Read(buffer, cb, bytesRead); //read block
 read = Marshal.ReadInt32(bytesRead); //obtain amount of data read
 }
 finally
 {
 Marshal.FreeCoTaskMem(bytesRead); //always clear COM memory (its not cleared in GC)
 }
 outStream.Write(buffer, 0, (int)read); //write buffer to out stream
} while (read > 0); //continue till something can be read
//do something with outStream