Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
360 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...