I am writing code to check whether a file exists or not. If the file exists it should throw a WebException. The code is below; if I run this code in .NET 3.5 it throws a WebException, but if use .NET 4.0 the exception is not thrown. I want the exception to be thrown so I can validate the file's existence.
bool IsExists = true;
try
{
    // string ftpServer = "FTP://111.111.111.111/16FebTo15Mar/Backup/MT_Backup/";
    string userName = "gff";
    // string filename = "sachin";
    string password = "gff@123";
    string ftppath= "FTP://111.111.111.111/16FebTo15Mar/Backup/MT_Backup/bh/"; 
                    // Ftpurl + new FileInfo(EmpFldr).Name + "/";
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftppath);
    request.Credentials = new NetworkCredential(userName, password);
    request.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
    // request.Method = WebRequestMethods.Ftp.MakeDirectory;
    FtpWebResponse response = (FtpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
    IsExists = false;
}
return IsExists;
 
     
     
    