This C# method will help you to copy a given stream file to another stream file. Just pass the source and destination streams and you will get stream copied into destination one.
/// <summary>
/// Copies the contents of one stream to another.
/// </summary>
/// <param name="source">The stream to copy from</param>
/// <param name="dest">The destination stream</param>
/// <remarks>Copying starts at the current stream positions</remarks>
public static void CopyStreams(Stream source, Stream dest)
{
byte[] buffer = new byte[64 * 1024];
int nRead = source.Read(buffer, 0, buffer.Length);
while (nRead != 0)
{
dest.Write(buffer, 0, nRead );
nRead = source.Read(buffer, 0, buffer.Length);
}
}
No comments:
Post a Comment