c#

位置:IT落伍者 >> c# >> 浏览文章

c#判断远程文件是否存在


发布日期:2018年03月31日
 
c#判断远程文件是否存在

//:

public static bool IsExist(string uri)

{

HttpWebRequest req = null;

HttpWebResponse res = null;

try

{

req = (HttpWebRequest)WebRequestCreate(uri);

reqMethod = HEAD;

reqTimeout = ;

res = (HttpWebResponse)reqGetResponse();

return (resStatusCode == HttpStatusCodeOK);

}

catch

{

return false;

}

finally

{

if (res != null)

{

resClose();

res = null;

}

if (req != null)

{

reqAbort();

req = null;

}

}

}

//:

private bool UrlExistsUsingXmlHttp(string url)

{

//注意此方法需要引用Msxmldll

MSXMLXMLHTTP _xml();

_xmlhttpopen(HEAD url false null null);

_xmlhttpsend();

return (_xmlhttpstatus == );

}

//:

private bool UrlExistsUsingSockets(string url)

{

if (urlStartsWith(//)) url = urlRemove( //Length);

try

{

SystemNetIPHostEntry ipHost =SystemNetDnsGetHostEntry(url);// SystemNetDnsResolve(url);

return true;

}

catch (SystemNetSocketsSocketException se)

{

SystemDiagnosticsTraceWrite(seMessage);

return false;

}

}

上一篇:C#创建简单的验证码操作

下一篇:C#里面中将字符串转为变量名