#region 判断远程文件是否存在
/// <summary>
/// 判断远程文件是否存在
/// </summary>
///<param name="fileurl">
/// <returns></returns>
public static bool remotefileexists(string fileurl)
{
httpwebrequest re = null;
httpwebresponse res = null;
try
{
re = (httpwebrequest)webrequest.create(fileurl);
res = (httpwebresponse)re.getresponse();
if (res.contentlength != 0)
{
//messagebox.show("文件存在");
return true;
}
}
catch (exception)
{
//messagebox.show("无此文件");
return false;
}
finally
{
if (re != null)
{
re.abort();//销毁关闭连接
}
if (res != null)
{
res.close();//销毁关闭响应
}
}
return false;
}
#endregion
以上就是c# 判断远程文件是否存在的内容。