Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > address check

Reply
Thread Tools

address check

 
 
Bert
Guest
Posts: n/a
 
      12-17-2006
Hi

I am looking for a function in asp.net/vb.net to check a web address. I want
to check whether the url is really existing. For example
Function(http://www.prut.comm/ ) = false

thanks

B


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      12-17-2006
"Bert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> I am looking for a function in asp.net/vb.net to check a web address. I
> want to check whether the url is really existing. For example
> Function(http://www.prut.comm/ ) = false


Apologies that this is in C#, not VB.NET, but it should be easy enough to
convert:


using System.Net;
using System.Text;

string strURL = "http://www.prut.comm";
using (WebClient objWebClient = new WebClient())
{
using (StreamReader objStreamReader = new
StreamReader(objWebClient.OpenRead(strURL)))
{
// do nothing here unless you want to do more than just "ping" the
URL
}
}

If no response is received from the URL, the above code will generate a
System.Net.WebExeception with the message (in this particular case):
"The remote name could not be resolved: 'www.prut.comm'"

Surround the above with a try...catch and check explicitly for a
System.Net.WebException.

N.B. there may be more elegant ways of "pinging" a URL...


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      12-17-2006
Try this (from
http://geekswithblogs.net/azamsharp/...8/81251.aspx):

private bool DoesUrlExists(string url)
{
bool urlExists = false;
WebRequest req = WebRequest.Create(url);

try
{
HttpWebResponse response = (HttpWebResponse) req.GetResponse();
urlExists = true;
}
catch (System.Net.WebException ex)
{

}

return urlExists;
}


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


"Bert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> I am looking for a function in asp.net/vb.net to check a web address. I
> want to check whether the url is really existing. For example
> Function(http://www.prut.comm/ ) = false
>
> thanks
>
> B
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to selecet check box in the data grid ?? only one check box mit ASP .Net 1 01-25-2006 06:47 PM
how to check all check boxes in repeater control kris ASP .Net 1 09-22-2005 07:16 PM
how to check all check boxes in repeater control kris ASP .Net 0 09-22-2005 06:29 PM
how to check all check boxes in repeater control kris ASP .Net 0 09-22-2005 06:29 PM
.Net Pro include Visual Source Safe or other Code Check in Check out software? Davisro ASP .Net 1 06-14-2004 03:23 PM



Advertisments