I found upload code and this code contains the Stream.CopyTo
method.
Example:
file.Stream.CopyTo(requestStream); // .NET Framework 4.0
How can I copy "file.Stream" to "requestStream"?
You can't, basically. It's only implemented in .NET 4. You can write a similar method yourself though... and even make it an extension method:
// Only useful before .NET 4
public static void CopyTo(this Stream input, Stream output)
{
byte[] buffer = new byte[16 * 1024]; // Fairly arbitrary size
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With