George George

George George

  • NA
  • 778
  • 0

file upload error

Feb 7 2009 8:44 AM

(sorry I ask again, not resolved for a week before.)

Hello everyone,

Here is my code at both client side and server side. My code is simple, just upload a file to an ASP.Net web site.

My client code throws exception when it works on Vista (x64, Enterprise, SP1), but works fine on Windows Server 2003.

Any ideas?

10.10.12.162 is my server address.

[Code]
Client:

       static void Main(string[] args)
        {
            Console.Write("\nPlease enter the URI to post data to : ");
            String uriString = Console.ReadLine();

            WebClient myWebClient = new WebClient();

            Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URI");
            string fileName = Console.ReadLine();
            Console.WriteLine("Uploading {0} to {1} ...", fileName, uriString);

            DateTime begin = DateTime.Now;

            byte[] responseArray = null;
            try
            {
                responseArray = myWebClient.UploadFile(uriString, fileName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.ToString());
            }

            DateTime end = DateTime.Now;

            Console.WriteLine("Elapsed time is: {0}", (end - begin).TotalMilliseconds);
        }

Server:

    public partial class FileUploadHandler : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (string f in Request.Files.AllKeys)
            {
                HttpPostedFile file = Request.Files[f];
                file.SaveAs("D:\\UploadFile\\UploadedFiles\\" + file.FileName);
            }
        }
    }

Exception from client side:

Unable to connect to the remote server
System.Net.WebException: Unable to connect to the remote server ---> System.Net.
Sockets.SocketException: No connection could be made because the target machine
actively refused it 10.10.12.162:1031
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock
et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state,
IAsyncResult asyncResult, Int32 timeout, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.WebClient.UploadFile(Uri address, String method, String fileNam
e)
   at FileUploadClient.Program.Main(String[] args) in D:\UploadFile\FileUploadClient\Program.cs:line 30
[/Code]

regards,
George