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

lianzy 2006-10-13 04:47:55
刚才提出“求下面vb调用dll改成c#调用dll的函数”
http://community.csdn.net/Expert/topic/5080/5080678.xml?temp=.3621179
已解决

[DllImport( "shlwapi.dll" )]
private extern static int PathFileExistsA ( string pszPath );


但发现在c#运行中只能判断自己电脑中的文件是否存在,而判断不了网站里的文件是否存在
也就是说用这个函数判断网站上的文件返回值都不存在。

谁能帮我解决这个问题。
...全文
430 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
viena 2006-10-13
  • 打赏
  • 举报
回复
string url ="";//你的网址
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse();
if(myRes.ContentLength==0)//文件不存在
buyaowen 2006-10-13
  • 打赏
  • 举报
回复
mark
wtoeb 2006-10-13
  • 打赏
  • 举报
回复
try
{
System.Net.WebRequest s=System.Net.WebRequest.Create(URL);
s.Timeout=10000;
System.Net.WebResponse a=s.GetResponse();
return true;
}
catch
{
return false;
}
陈义源 2006-10-13
  • 打赏
  • 举报
回复
用这个试试:
string url ="";//你的网址
url = System.Web.HttpUtility.UrlEncode(url,System.Text.Encoding.GetEncoding("GB2312"));
string temp="";
System.Net.WebRequest wreq=System.Net.WebRequest.Create(url);
System.Net.HttpWebResponse wresp=(System.Net.HttpWebResponse)wreq.GetResponse();
System.IO.Stream s=wresp.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(s,System.Text.Encoding.GetEncoding("gb2312"));
temp=sr.ReadToEnd();//temp为你读的网页内容.
//如果temp为空则没有找到文件
owennol 2006-10-13
  • 打赏
  • 举报
回复
File.exist();
xingyaohua 2006-10-13
  • 打赏
  • 举报
回复
up

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧