C# – WebClient.UploadFile issue

asp.netcnetwebclient

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

Best Answer

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

Related Topic