Creating a stream out of an httppostedfile always returns an empty file

I have the following code:

file.InputStream.Seek(0,0);
Stream s = file.InputStream
s.Position = 0;
s = File.Create(path);

My goal is for the final output to be a duplicate of the original file. Using file.SaveAs(path) successfully does this. However converting it to a stream and then trying to create the file does not. Is there something completely obvious that I'm missing or is there a bigger problem?

Jon Skeet
people
quotationmark

The problem is this line:

s = File.Create(path)

That doesn't do what you want it to. That's creating a new stream - at which point you're ignoring the old one entirely.

You probably want something like:

using (var output = File.Create(path))
{
    file.InputStream.CopyTo(output);
}

people

See more on this question at Stackoverflow