Hi,
Does there has any easy way to check if a specified url is a valid one (both the format should be valid but also the specified path / file is available)?
Thanks in advance!
Henry 4 10739
You could always pop the url into a System.Net.WebClient object. If
the url is invalid, or the url is unreachable, the object will throw a
WebException. Of course, this doesn't distinguish between a bad URL
and a bad network connection, for that you would need some additional
tests, perhaps fetching from a known good URL.
HTH,
--
Scott http://www.OdeToCode.com
On Tue, 27 Apr 2004 11:46:53 +0800, "Henry Jia" <ji***@hotmail.com>
wrote: Hi,
Does there has any easy way to check if a specified url is a valid one (both the format should be valid but also the specified path / file is available)?
Thanks in advance!
Henry
What's the meaning of "pop the url"? and how about the time used for check?
Thank you!
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message news:00********************************@4ax.com...
You could always pop the url into a System.Net.WebClient object. If
the url is invalid, or the url is unreachable, the object will throw a
WebException. Of course, this doesn't distinguish between a bad URL
and a bad network connection, for that you would need some additional
tests, perhaps fetching from a known good URL.
HTH,
--
Scott http://www.OdeToCode.com
On Tue, 27 Apr 2004 11:46:53 +0800, "Henry Jia" <ji***@hotmail.com>
wrote: Hi,
Does there has any easy way to check if a specified url is a valid one (both the format should be valid but also the specified path / file is available)?
Thanks in advance!
Henry
Hi Henry,
So far this method has worked for me, it connects to a DNS server and
checks the name. I strip any http:// headers or folder structures before
passing it to ValidateURL.
// check to see if we can find the url
private bool ValidateURL(string u)
{
try
{
Dns.GetHostByName(u);
}
catch
{
try // maybe we passed an ip address
{
Dns.GetHostByAddress(u);
}
catch
{
return false;
}
}
return true;
}
Happy coding!
Morten Wennevik [C# MVP]
Hi Henry,
Sorry for the slang.
Here is a sample:
WebClient wc = new WebClient();
Stream stream = wc.OpenRead("http://www.microsoft.com");
stream.ReadByte();
stream.Close();
If you pass the URL into the OpenRead method, and the code executes
without an exception, then you can be sure that the URL is well formed
and valid, that the server is reachable, and that the path and
filename exist on the server.
As for timing, it won't be as fast as verifying the URL format with a
regular expression, but the only way to be sure you have a valid path
to a file that exists on a remote server is to go to the server and
ask for the file.
HTH,
On Tue, 27 Apr 2004 13:24:08 +0800, "Henry Jia" <ji***@hotmail.com>
wrote: What's the meaning of "pop the url"? and how about the time used for check?
Thank you!
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message news:00********************************@4ax.com... You could always pop the url into a System.Net.WebClient object. If the url is invalid, or the url is unreachable, the object will throw a WebException. Of course, this doesn't distinguish between a bad URL and a bad network connection, for that you would need some additional tests, perhaps fetching from a known good URL.
HTH,
-- Scott http://www.OdeToCode.com
On Tue, 27 Apr 2004 11:46:53 +0800, "Henry Jia" <ji***@hotmail.com> wrote:
>Hi, > > Does there has any easy way to check if a specified url is a valid one (both the format should be valid but also the specified path / file is available)? > > Thanks in advance! > >Henry
--
Scott http://www.OdeToCode.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Craig Bailey |
last post by:
Someone please explain what alternate universe I fell into this
afternoon when PHP started telling me that 2 doesn't equal 2.
Not sure about you, but when I run this, it tells me 59001.31 doesn't...
|
by: Askari |
last post by:
Hi,
How do for do a "select()" on a CheckButton in a menu (make with
add_checkbutton(....) )?
I can modify title, state, etc but not the "check state". :-(
Askari
|
by: Edward |
last post by:
The following html / javascript code produces a simple form with check
boxes. There is also a checkbox that 'checks all' form checkboxes
hotmail style:
<html>
<head>
<title></title>
</head>...
|
by: Tony Johnson |
last post by:
Can you make a check box very big? It seems like when you drag it
bigger the little check is still the same size.
Thank you,
*** Sent via Developersdex http://www.developersdex.com ***...
|
by: Travis.Box |
last post by:
I have an MS Access userform with 16 Check Boxes. Each of the
checkboxes has a different option value, which coincides with the Check
Box name (eg. cb01.OptionValue = 1). At the bottom of the...
|
by: scprosportsman |
last post by:
Please help guys, i am trying to set up a database here at work and im
fairly new to access in terms of writing functions and queries and
stuff. I have 2 different places on my design that will...
|
by: Chris Davoli |
last post by:
How do you enable a check box in the GridView. I selected Checkbox Field in
the Columns of the GridView, and the check box shows up in the Grid view, but
it is disabled. How do I enable it so I can...
|
by: Brian Tkatch |
last post by:
Is there a way to check the order in which SET INTEGRITY needs to be
applied? This would be for a script with a dynamic list of TABLEs.
B.
|
by: starke1120 |
last post by:
Im creating a check in – check out database for RF guns. I have a
table that contains models.
ID (primary key)
Model
A table that contains Gun Details
ID (primary key)
Model_id...
|
by: ghjk |
last post by:
my php page has 7 check boxes. I stored checked values to database and retrive as binary values. This is the result array
Array ( => 0 => 1 => 0 => 1 => 0 => 0 => 1 )
1 means checked....
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |