Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3605558
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:08:20+00:00 2026-05-18T21:08:20+00:00

I never used the WebClient before and I’m not sure if I should check

  • 0

I never used the WebClient before and I’m not sure if I should check the response from the server to know if the upload was successful or if I can let the file as uploaded if there is no exception.

If I should check the response how can I do that? Parsing resposeHeaders property?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:08:20+00:00Added an answer on May 18, 2026 at 9:08 pm

    The UploadFile method returns a byte[] that contains the response the remote server returned. Depending on how the server manages responses to upload requests (and error conditions (see note 1 below)) you will need to check that response. You can get the string response by converting it to a string, for example this will write the response to the console window:

    byte[] rawResponse = webClient.UploadFile(url,fileName);
    Console.WriteLine("Remote Response: {0}", System.Text.Encoding.ASCII.GetString(rawResponse));
    

    That said if the remote server returns anything other than a HTTP 200 (i.e. success) the call to UploadFile will throw a WebException. This you can catch and deal with it whatever manner best suits your application.

    So putting that all together

    try
    {
        WebClient webClient = new WebClient();
        byte[] rawResponse = webClient.UploadFile(url,fileName);
    
        string response = System.Text.Encoding.ASCII.GetString(rawResponse);
    
        ...
        Your response validation code
        ...
    }
    catch (WebException wexc)
    {
        ...
        Handle Web Exception
        ...
    }
    

    Note 1 As an example I have a file upload service that will never issue anything other than a HTTP 200 code, all errors are caught within the service and these are “parsed” into an XML structure that is returned to the caller. The caller then parses that XML to validate that the upload was successful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never used CI tools before, but from what I've read, I'm not sure
I've never used HTTP Handlers before, and I've got one working, but I'm not
I've never used php before and am trying to connect to a SQL Server
I've never used NSCoding before and I'm very confused about how it should be
Never used fwrite(), so I'm not sure exactly what I'm doing wrong. I'm just
Have never used sass before. On my production server having to switch chmod 644
I've never used Java AWT before and now I've got a piece of code
I have never used array_combine before and I am getting a Boolean instead of
I never used CRONs and I don't know hot to set up one so
I never used Settings class before but I found some articles on CodeProject which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.