Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Upload file using webclient

Upload file using webclient

Scheduled Pinned Locked Moved C#
sysadminhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vanikanc
    wrote on last edited by
    #1

    Hi, I am trying to upload a file from my laptop to remote development server. It keeps coming back with either 404 error or 405 error. I am able to download a file with no issues at at all. all I have is a form with a button on it, and clicking on button invokes the below. I get the message, "Upload Complete" but the file does not exist on the remote server.

    private void button3_Click(object sender, EventArgs e)
    {
    WebClient wcUpload = new WebClient();
    NetworkCredential myNwc = new NetworkCredential("username", "password");
    wcUpload.Credentials = myNwc;

            wcUpload.UploadFile("http://:85", "POST", "C:\\\\projects\\\\ProgressBar\\\\file\_0122.csv");          
            MessageBox.Show("Upload complete!!");
        }// end button3\_Click
    
    L K 2 Replies Last reply
    0
    • V vanikanc

      Hi, I am trying to upload a file from my laptop to remote development server. It keeps coming back with either 404 error or 405 error. I am able to download a file with no issues at at all. all I have is a form with a button on it, and clicking on button invokes the below. I get the message, "Upload Complete" but the file does not exist on the remote server.

      private void button3_Click(object sender, EventArgs e)
      {
      WebClient wcUpload = new WebClient();
      NetworkCredential myNwc = new NetworkCredential("username", "password");
      wcUpload.Credentials = myNwc;

              wcUpload.UploadFile("http://:85", "POST", "C:\\\\projects\\\\ProgressBar\\\\file\_0122.csv");          
              MessageBox.Show("Upload complete!!");
          }// end button3\_Click
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What page are you uploading to? Default.aspx? Is it a 404 or a 405? One would mean your page doesn't exist, the other would mean your "POST"-ing something that expects a "GET" (or the other way 'round, I keep forgetting)

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      V 1 Reply Last reply
      0
      • L Lost User

        What page are you uploading to? Default.aspx? Is it a 404 or a 405? One would mean your page doesn't exist, the other would mean your "POST"-ing something that expects a "GET" (or the other way 'round, I keep forgetting)

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        V Offline
        V Offline
        vanikanc
        wrote on last edited by
        #3

        Thank you for your reply. I am just trying to upload a simple .csv file from my project.

        L 1 Reply Last reply
        0
        • V vanikanc

          Thank you for your reply. I am just trying to upload a simple .csv file from my project.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          vanikanc wrote:

          I am just trying to upload a simple .csv file from my project.

          So I noticed. Again, to which asp-page (the one with the upload-control)? Default.aspx? And, is it a 404 or a 405-error? They're kinda different, so you'd better check.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          • V vanikanc

            Hi, I am trying to upload a file from my laptop to remote development server. It keeps coming back with either 404 error or 405 error. I am able to download a file with no issues at at all. all I have is a form with a button on it, and clicking on button invokes the below. I get the message, "Upload Complete" but the file does not exist on the remote server.

            private void button3_Click(object sender, EventArgs e)
            {
            WebClient wcUpload = new WebClient();
            NetworkCredential myNwc = new NetworkCredential("username", "password");
            wcUpload.Credentials = myNwc;

                    wcUpload.UploadFile("http://:85", "POST", "C:\\\\projects\\\\ProgressBar\\\\file\_0122.csv");          
                    MessageBox.Show("Upload complete!!");
                }// end button3\_Click
            
            K Offline
            K Offline
            Keith Barrow
            wrote on last edited by
            #5

            The "Upload complete" doesn't mean a thing it'll only not show if something throws an error beforehand. UploadFile only thows in the following circumstances:

            • The Address or Filename being null
            • The URI formed by combining BaseAddress, and address is invalid.
            • fileName is null, is Empty, contains invalid characters, or does not exist.
            • An error occurred while uploading the file.
            • There was no response from the server hosting the resource.
            • The Content-type header begins with multipart.

            None of which apply to your code. You might get better explanation of what is happing by reading the returned byte array:

            byte[] responseArray = myWebClient.UploadFile(....);
            string response = System.Text.Encoding.ASCII.GetString(responseArray)

            In any case, it looks like the server won't allow posts to the root which is why you are getting the 405. It might also be worth checking something is listening on port 85, and it isn't being blocked by a firewall.

            Sort of a cross between Lawrence of Arabia and Dilbert.[^]
            -Or-
            A Dead ringer for Kate Winslett[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups