system.exception 不包含 Response 的定义是什么?
what does system.exception does not contain a definition for Response?
我是编程新手。我正在开发 ftp 应用程序。
为此,我需要查找 ftp 中的文件是否存在。我已经编写了以下代码来查找文件是否存在。但是发生错误
System.exception
不包含响应
的定义
catch (WebException ex)
{
FtpWebResponse response = (FtpWebResponse)ex.Response;
if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
return false;
}
我认为你的完整代码是
var request = (FtpWebRequest)WebRequest.Create
("ftp://ftp.domain.com/doesntexist.txt");
request.Credentials = new NetworkCredential("user", "pass");
request.Method = WebRequestMethods.Ftp.GetFileSize;
try
{
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
FtpWebResponse response = (FtpWebResponse)ex.Response;
if (response.StatusCode ==
FtpStatusCode.ActionNotTakenFileUnavailable)
{
//Does not exist
}
}
catch(Exception e)
{
}
您是否尝试添加所有命名空间,特别是
using System.Net;
我是编程新手。我正在开发 ftp 应用程序。 为此,我需要查找 ftp 中的文件是否存在。我已经编写了以下代码来查找文件是否存在。但是发生错误
System.exception
不包含响应
catch (WebException ex)
{
FtpWebResponse response = (FtpWebResponse)ex.Response;
if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
return false;
}
我认为你的完整代码是
var request = (FtpWebRequest)WebRequest.Create
("ftp://ftp.domain.com/doesntexist.txt");
request.Credentials = new NetworkCredential("user", "pass");
request.Method = WebRequestMethods.Ftp.GetFileSize;
try
{
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
FtpWebResponse response = (FtpWebResponse)ex.Response;
if (response.StatusCode ==
FtpStatusCode.ActionNotTakenFileUnavailable)
{
//Does not exist
}
}
catch(Exception e)
{
}
您是否尝试添加所有命名空间,特别是
using System.Net;