Stream.CopyTo was introduced in .NET 4. Since you're targeting .Net 2.0, it's not available. Internally, CopyTo
is mainly doing this (although has extra error handling) so you can just use this method. I've made it an extension method for convenience.
//it seems 81920 is the default size in CopyTo but this can be changed
public static void CopyTo(this Stream source, Stream destination, int bufferSize = 81920)
{
byte[] array = new byte[bufferSize];
int count;
while ((count = source.Read(array, 0, array.Length)) != 0)
{
destination.Write(array, 0, count);
}
}
So you can simply do
using (var ms = new MemoryStream())
{
fu.PostedFile.InputStream.CopyTo(ms);
ms.Position = 0;
img = new System.Drawing.Bitmap(ms);
}