Reputation: 603
How do I catch the ftp when it is unable to connect? I tried this, but had no luck.
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);
}
Error 2 The name 'file' does not exist in the current context
Error 3 The name 'ftpStream' does not exist in the current context
Warning 1 The variable 'Chosen_File' is assigned but its value is never used
Upvotes: 0
Views: 242
Reputation: 59055
The error you're receiving is because you are trying to use the variables ftpStream
and file
outside of the try {}
block. Here's some reading from MSDN on the subject of try/catch blocks.
Upvotes: 1