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

//引用System.Net
using system.net


try
{
        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.qujingwang.com/defaulti.aspx");
        myReq.Method = "HEAD";
        HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse();
        if(myRes.StatusCode == HttpStatusCode.OK)   //判断如果文件存在,执行以下语句
        {
                pnl.Visible = true;
                pnl1.Visible = false;    
         }
}
catch     //如果远程文件defaulti.asp 不存在,执行以下语句
{
          pnl.Visible = false;
          pnl1.Visible = true;
}

你可能感兴趣的:(代码收藏)