Click here to Skip to main content
12,757,220 members (38,476 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I had used the following code but it executes with error msg texted on catch.source file exists on drive F and i have a folder named as New in C:/Wamp/www/New where i want to upload the file for test.the code is as...
private void upload_Click(object sender, EventArgs e)
label2.Text = "Uploading successfully completed...";
public void Upload(string fileToUpload)

FileInfo toUplaod = new FileInfo(fileToUpload);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("" + toUplaod.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
//request.Credentials = new NetworkCredential("USERNAME","PASSWORD");
Stream ftpstream = request.GetRequestStream();
FileStream file = File.OpenRead(fileToUpload);
int length = 1024;
byte[] buffer = new byte[length];
int bytesRead = 0;

bytesRead = file.Read(buffer, 0 ,length);
ftpstream.Write(buffer, 0, bytesRead);
while (bytesRead != 0);

MessageBox.Show("Error ! connecting server..itni jaldi nhi chalunga Sir g..");

Thank you....
Posted 30-Dec-12 21:07pm
Updated 31-Dec-12 0:31am
Are you really running an HTTP server and service such a strange directory?
OriginalGriff 31-Dec-12 2:18am
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps, if you take the comments out and tell us what problem you are getting it would help? At the moment all we have is a small chunk of simple code, and "It don't work" which is not helpful as errors messages go...
Use the "Improve question" widget to edit your question and provide better information.
@RahulTripathi17 31-Dec-12 5:34am
thank u sir to guide me ...if i use Webclient class to upload a file on server how should i code for that.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I cannot believe that not only you are running HTTP server on "http://localhost", on default port; and that your have a sub-directory named "/". It's more likely that you do not quite understand the URI scheme; and you actual URL is "http://localhost/New".

Please see for more information:[^].

I also not quite sure that you are running any HTTP server at all. Did you install one? You never mentioned it, and I suspect you don't quite understand how it works. Sorry if I'm wrong about it.

Also, I want to note that there are no situations where using a hard-coded URL is useful. However, if this is just a preliminary test, it's probably OK.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100