Upload file using webclient
-
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
-
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
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[^]
-
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[^]
-
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[^]
-
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
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[^]