3 Replies - 10557 Views - Last Post: 16 January 2009 - 10:56 AM Rate Topic: -----

#1 skyHigh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 116
  • Joined: 01-October 07

Uploading file to web server?

Posted 15 January 2009 - 06:59 PM

I'm trying to save a text file to a web server. In the web, I can manually upload file and it works, but programmatically doesn't. I use the code below.

		private void SaveTToWeb()
		{
			try
			{
				//create WebClient object
				WebClient client = new WebClient();
				
				string myFile = @"C:\Draft_3.txt";

				client.Credentials = CredentialCache.DefaultCredentials;

				client.UploadFile(@"http://myweb.com/projects/idl/Draft Results/RK/", myFile);
				
				client.Dispose();
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
		}




when I run, it doesn't give any error, but when I check the website by refreshing and go previous address, but the file doesn't upload.

can anyone help?

thanks.

Is This A Good Question/Topic? 1

Replies To: Uploading file to web server?

#2 skyHigh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 116
  • Joined: 01-October 07

Re: Uploading file to web server?

Posted 16 January 2009 - 10:43 AM

		private void SaveTToWeb()
		{
			try
			{
				//create WebClient object
				WebClient client = new WebClient();
				
				string myFile = @"C:\Draft_3.txt";

				client.Credentials = CredentialCache.DefaultCredentials;

				client.UploadFile(@"http://myweb.com/projects/idl/Draft Results/RK/myFile", "PUT", myFile);
				
				client.Dispose();
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
		}




my previous code didn't work because I didn't include my file name at the end of URL, and need to add one more parameter "PUT" for the UploadFile function, so now it works now after searching on google.
Was This Post Helpful? 0
  • +
  • -

#3 Kuggi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 80
  • Joined: 16-January 09

Re: Uploading file to web server?

Posted 16 January 2009 - 10:51 AM

Nice that you find the error yourself.

Now i'm gonna look at your exsample code an find one of my own errors :D
Was This Post Helpful? 0
  • +
  • -

#4 skyHigh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 116
  • Joined: 01-October 07

Re: Uploading file to web server?

Posted 16 January 2009 - 10:56 AM

here is the links that I found my error from.
http://bytes.com/gro...ows-application

however if you upload your file with the FTP then you have use the example in these links:
http://blog.madskris...ad-in-C-20.aspx
http://www.vcskicks....ftp_upload.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1