您现在的位置是:首页 >

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

火烧 2023-03-17 00:14:35 1059
c#判断远程文件是否存在   // : u lic tatic ool I Exi t tri g uri { Htt We Reque t req = ull Htt We Re o e re =

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

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

  // :    public static bool IsExist(string uri)            {                HttpWebRequest req = null;                HttpWebResponse res = null;                try                {                    req = (HttpWebRequest)WebRequest Create(uri);                    req Method = HEAD ;                    req Timeout = ;                    res = (HttpWebResponse)req GetResponse();                    return (res StatusCode == HttpStatusCode OK);                }                catch                {                    return false;                }                finally                {                    if (res != null)                    {                        res Close();                        res = null;                    }                    if (req != null)                    {                        req Abort();                        req = null;                    }                }            }

  // :

  private bool UrlExistsUsingXmlHttp(string url)    {      //注意 此方法需要引用Msxml dll      MSXML XMLHTTP _xml();      _xml open( HEAD url false null null);      _xml send( );      return (_xml status == );    }

lishixinzhi/Article/program/net/201311/11555  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码