Copy Stream and close
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
public static class StreamUtilities
{
public static long CopyStream(Stream Source, Stream Target, bool CloseStreams)
{
long lngBytesCopied = 0;
byte[] buffer = new byte[1024];
int intReadSize = buffer.Length;
while (true)
{
intReadSize = Source.Read(buffer, 0, intReadSize);
if (intReadSize == 0)
break;
Target.Write(buffer, 0, intReadSize);
lngBytesCopied += intReadSize;
}
Target.Flush();
if (CloseStreams)
{
Source.Close();
Target.Close();
}
return lngBytesCopied;
}
}
Related examples in the same category