[英]Code throwing WebException works in .NET 3.5 but not in 4.0
我正在編寫代碼以檢查文件是否存在。 如果文件存在,則應拋出WebException。 代碼如下; 如果我在.NET 3.5中運行此代碼,則會引發WebException,但如果使用.NET 4.0,則不會引發異常。 我希望引發異常,以便可以驗證文件的存在。
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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.