file upload error
-
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 -
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 -
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