Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. file upload error

file upload error

Scheduled Pinned Locked Moved C#
csharpasp-netdesignsysadminwindows-admin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    George_George
    wrote on last edited by
    #1

    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.

    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\FileUploa

    A 1 Reply Last reply
    0
    • G George_George

      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.

      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\FileUploa

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      It could be a firewall blocking the connection. Try disabling the firewall for a moment and see if it connects. If it does work then you will need to configure your firewall to allow the connection.

      My current favourite word is: Delicious!

      -SK Genius

      Game Programming articles start -here[^]-

      G 1 Reply Last reply
      0
      • A Anthony Mushrow

        It could be a firewall blocking the connection. Try disabling the firewall for a moment and see if it connects. If it does work then you will need to configure your firewall to allow the connection.

        My current favourite word is: Delicious!

        -SK Genius

        Game Programming articles start -here[^]-

        G Offline
        G Offline
        George_George
        wrote on last edited by
        #3

        Thanks SK, 1. Do you mean checking firewall at client side or server side? 2. I have checked my firewall is off at server side, and the server is Windows Server 2003. I have made another test which using browser from another machine to access http://10.10.12.162:1031/<some existing URL>, and IE on another machine can not access the URL. But IE on the same machine (which the server runs) could access the URL. I have two further questions, A. If the firewall is off (checked from Control Panel --> Firewalls), any other points to check which may block network connection? B. I run the web server from Visual Studio directly by pressing F5 on the Windows Server 2003 machine, other than run from IIS web server. I am not sure whether running from Visual Studio will only enable client to access locally? regards, George

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups