views:

157

answers:

1

Hello everyone,

I am using VSTS 2008 + C# + .Net 3.5 + ASP.Net. I am using WebClient.UploadFile to upload file to a server running with ASP.Net (I use http post to upload the file to a aspx url). My question is, how to save the content of the file at server side? I find from server side, if I simply save HttpContext.Current.Request.InputStream, additional request headers (besides file content) will be saved at server side.

EDIT 1:

I have tried I need to have some code like this to receive file at server side? Is that correct code?

    foreach (string f in Request.Files.AllKeys)
    {
        HttpPostedFile file = Request.Files[f];
        file.SaveAs(@"D:\FileUpload\UploadFile.dat");
    }

thanks in advance, George

+2  A: 

You can read the stream into a byte array and then save the byte array in a varbinary(max) field in SQL server.

Shiraz Bhaiji
Sorry maybe I have not made myself understood. I mean at server side, how to receive the file content (which is using WebClient.UploadFile to upload)?
George2
I have found a solution by myself. I have posted my solution in EDIT 1 section of my post. Could you review whether my code is correct please? Thanks!
George2
From your code it looks like the second file will overwrite the first
Shiraz Bhaiji
Yes, it is just for proof of concept purpose. For other parts like how to receive file, is my code correct? Thanks.
George2