I’ve got the following Stream code . and I feel that it’s really old and ugly and that there should be a cleaner way to do this.
// Write the current chunk to the stream.
using (var fileStream = new FileStream(tempPath, currentChunk == 0 ?
FileMode.Create :
FileMode.Append))
{
var buffer = new byte[uploadedFile.Length];
uploadedFile.Read(buffer, 0, buffer.Length);
fileStream.Write(buffer, 0, buffer.Length);
}
What is it doing?
I upload a file in chunks. So we either create a new file (when we’re at the first chunk, ie chunk == 0) .. or we append the chunk data to an existing file.
I feel that the 3 lines are obsolete and there’s a better method that’s available to be used.
Yes / No / Maybe?
EDIT: .NET 4.0 is fine by me 🙂
Might
Stream.CopyTowork for you?For what it’s worth, though, I don’t think this API existed until .NET 4.0.