0

I'm uploading a file using this code:

WebClient myWebClient = new WebClient();
byte[] responseArray = myWebClient.UploadFile(string.Format("http://{0}/WebApplication/Default.aspx", this.WebServerName), "POST", filePath);

I receive the file in Page_Load() :

foreach (string f in Request.Files.AllKeys)
{
    HttpPostedFile file = Request.Files[f];
    Utils.ProcessUpload(file);
    Response.Status = "success";
}

I would like to read the status from responseArray so I can make a decision based on the uploads status. I'm not figuring out how to get the Status from the responseArray.

EDIT: The example here doesn't provide much help. it does display the response array

visc
  • 4,794
  • 6
  • 32
  • 58

1 Answers1

0

In responseArray is only body of the response not the status and headers you are interesting on. You can be sure that if UploadFile method returns status will be success 2xx or others. If response will be 4xx (error) than WebException is thrown and you can read status from exception:

Check this link how to handle this exception

If you want more precise status handling, you have to use WebRequest / WebResponse directly.

Community
  • 1
  • 1
Aik
  • 3,528
  • 3
  • 19
  • 20