2011-11-22 92 views
0

如何在無法連接時捕獲ftp?我試過這個,但沒有運氣。c#捕獲ftp錯誤

try 
     { 
     Stream ftpStream = request.GetRequestStream(); 
     FileStream file = File.OpenRead(this.txtFile.Text); 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine("Unable to upload file! Please close out window and try again later. " + ex.Message); 
     } 

錯誤2名稱「文件」不存在於當前上下文存在

錯誤3「ftpStream」名稱不在當前上下文

警告1所述的可變「Chosen_File」存在被分配但其值不會被使用

+0

您收到的錯誤是什麼? –

+0

查看DBM的答案 - 這裏發佈的任何代碼都沒有拋出異常。 – ChrisBD

回答

1

您收到的錯誤是因爲您嘗試使用try {}塊之外的變量ftpStreamfileHere's一些關於try/catch塊主題的MSDN讀物。