473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

WebClient.UploadFile problem

25
Hi, i am using WebClient.UploadFile to upload a file on my web page, code:
Expand|Select|Wrap|Line Numbers
  1. WebClient webClient = new WebClient();
  2. webClient.Credentials = new NetworkCredential(userName, pass);
  3. webClient.UploadFile("http://www.etfos.hr/~dhuis/test.txt", @"c:\test.txt");
  4.  
i get an error "The remote server returned an error: (404) FIle not found"
my web page is http://www.etfos.hr/~dhuis
permissions are all enabled
i tried with httpwebrequest class and i get the same error
i can upload with ftpwebrequest but then it is slow.
Any suggestions?
May 5 '08 #1
5 10650
Svinja
25
Do i have to make some asp/php code to recieve it on my server? I thought http will do it for me like ftp does?
May 7 '08 #2
Frinavale
9,735 Expert Mod 8TB
Hi, i am using WebClient.UploadFile to upload a file on my web page, code:
Expand|Select|Wrap|Line Numbers
  1. WebClient webClient = new WebClient();
  2. webClient.Credentials = new NetworkCredential(userName, pass);
  3. webClient.UploadFile("http://www.etfos.hr/~dhuis/test.txt", @"c:\test.txt");
  4.  
i get an error "The remote server returned an error: (404) FIle not found"
my web page is http://www.etfos.hr/~dhuis
permissions are all enabled
i tried with httpwebrequest class and i get the same error
i can upload with ftpwebrequest but then it is slow.
Any suggestions?

I'm not clear on what you are doing.
The WebClient Class sends a local file to the resource you've specified...

The resource you've specified is:
"http://www.etfos.hr/~dhuis/test.txt"

This isn't a valid URI location to upload your file to....it cannot find "http://www.etfos.hr/~dhuis/test.txt" and so you are getting a 404 error.

Try instead:
"http://www.etfos.hr/dhuis/"

I'm not 100% sure this will work. But I am sure that you are using an invalid string to indicate the URL of the resource you want to upload the file to.

See the WebClient.UploadFile Method for examples on how to use this.

-Frinny
May 7 '08 #3
Svinja
25
I'm not clear on what you are doing.
The WebClient Class sends a local file to the resource you've specified...

The resource you've specified is:
"http://www.etfos.hr/~dhuis/test.txt"

This isn't a valid URI location to upload your file to....it cannot find "http://www.etfos.hr/~dhuis/test.txt" and so you are getting a 404 error.

Try instead:
"http://www.etfos.hr/dhuis/"

I'm not 100% sure this will work. But I am sure that you are using an invalid string to indicate the URL of the resource you want to upload the file to.

See the WebClient.UploadFile Method for examples on how to use this.

-Frinny
Thanks for your answer but i believe you are wrong, the uri is correct. "http://www.etfos.hr/~dhuis/test.txt" means that i want to put the file in
"http://www.etfos.hr/~dhuis/" and name it "test.txt". I believe i should have the receiving script on my web server, i will try to make one and post it if i succeed
May 7 '08 #4
Svinja
25
I was right, asp/php script is necessary:
c# code:
Expand|Select|Wrap|Line Numbers
  1. WebClient webClient = new WebClient();
  2. byte []responseBytes=webClient.UploadFile("http://www.etfos.hr/~dhuis/Upload.php", @"c:\data2.dat");
  3. String response = Encoding.Default.GetString(responseBytes);
  4. MessageBox.Show(response);
  5.  
php code(Upload.php):
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $uploadDir = 'Upload/'; 
  3. $uploadFile = $uploadDir . basename($_FILES['file']['name']);
  4. if (is_uploaded_file($_FILES['file']['tmp_name'])) 
  5. {
  6.     echo "File ". $_FILES['file']['name'] ." is successfully uploaded!\r\n";
  7.     if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) 
  8.     {
  9.         echo "File is successfully stored! ";
  10.     }
  11.     else print_r($_FILES);
  12. }
  13. else 
  14. {
  15.     echo "Upload Failed!";
  16.     print_r($_FILES);
  17. }
  18. ?>
  19.  
-Upload.php must be in "http://www.etfos.hr/~dhuis/"
-Upload directory must have write permission
May 7 '08 #5
Frinavale
9,735 Expert Mod 8TB
I was right, asp/php script is necessary:
c# code:
Expand|Select|Wrap|Line Numbers
  1. WebClient webClient = new WebClient();
  2. byte []responseBytes=webClient.UploadFile("http://www.etfos.hr/~dhuis/Upload.php", @"c:\data2.dat");
  3. String response = Encoding.Default.GetString(responseBytes);
  4. MessageBox.Show(response);
  5.  
php code(Upload.php):
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $uploadDir = 'Upload/'; 
  3. $uploadFile = $uploadDir . basename($_FILES['file']['name']);
  4. if (is_uploaded_file($_FILES['file']['tmp_name'])) 
  5. {
  6.     echo "File ". $_FILES['file']['name'] ." is successfully uploaded!\r\n";
  7.     if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) 
  8.     {
  9.         echo "File is successfully stored! ";
  10.     }
  11.     else print_r($_FILES);
  12. }
  13. else 
  14. {
  15.     echo "Upload Failed!";
  16.     print_r($_FILES);
  17. }
  18. ?>
  19.  
-Upload.php must be in "http://www.etfos.hr/~dhuis/"
-Upload directory must have write permission

Thanks for sharing your solution :)

-Frinny
May 8 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David W | last post by:
I am trying to upload a file from a user's system to my web server. I found code using the WebClient.UploadFile method. However, the uploaded file is from the server's hard drive not the user's...
0
by: Saverio Tedeschi | last post by:
Hi all gurus, forgive me if I submit a 2nd post, but I'm no more able to see my question. So: I wrote an Win app with embedded FTP client (well, made some cut and paste from others' projects :-))...
2
by: marfi95 | last post by:
Hello all. I'm not sure if this is the correct place to post this, but if not please let me know. This is my situation. I have a simple problem, but am having problems doing this. I'm...
1
by: Phillip N Rounds | last post by:
I'm having problems using the WebClient.UploadFile() command. I have MySender.ASPX which is supposed to upload two files to the server. There is also ConsumeFileUpload.aspx which is intended to...
5
by: linn | last post by:
The 'Address' parameter in the WebClient.UploadFile usually comes in the form of ie. http://server/Upload_File.aspx Hence my question, what is exactly the content of this Upload_File.aspx? Am i...
2
by: Daniel | last post by:
As you may have guessed I'm trying to upload a file to a php server using the WebClient.UploadFile function, however the function never returns. Instead it chews up memory (fairly slowly) until it...
2
by: UJ | last post by:
I'm trying to upload stuff using the UploadFile from WebClient and I've noticed that it adds header and footers to the stream. Is there any way to get rid of that automatically? I'm using...
6
by: =?Utf-8?B?U2NvdHQgVHJpY2s=?= | last post by:
I followed the instructions from MSDN for Webclient UploadFile and I get an error: Could not find file 'C:\testfile.xls'. If I add the file (c:\testfile.xls) to the server I do not get the error...
5
by: benmess | last post by:
This code snippet works fine on a localhost because the file you upload resides on the host machine (where FileServer.aspx is a new page invoked from the UploadFile call) function...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.