473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Load Web Page via Windows Form or Service

I want to write a simple class that loads a requested url and reports
success or failure. I plan to use this to monitor web sites on the web.

I would like to implement the class in a windows form and a service.

Any help would be appreciated.

scott
Nov 18 '05 #1
2 4212
You may be able to use the System.Net.WebClient to perform the task. But, if
you are running the code as a service make sure an account other than system
is specified or the service won't have access to resources off the machine.
HTH,
Jared

Shared Sub Main()
Console.WriteLine("Google: " &
CheckSite("http://www.google.com").ToString)
Console.WriteLine("MSN: " & CheckSite("http://www.msn.com").ToString)
Console.WriteLine("Bad URL: " &
CheckSite("http://www.thisisabadurl.com").ToString)
Console.ReadLine()
End Sub

Shared Function CheckSite(ByVal URL As String) As Boolean
Dim wcSiteStatus As New System.Net.WebClient
Dim stream As System.IO.Stream = New System.IO.MemoryStream
Dim reader As System.IO.StreamReader
Try
With wcSiteStatus
stream = .OpenRead(URL)
reader = New System.IO.StreamReader(stream)
If reader.Peek > 0 Then
Return True
Else
Return False
End If
End With
Catch ex As Exception
Return False
Finally
If Not reader Is Nothing Then reader.Close()
wcSiteStatus.Dispose()
End Try
End Function

"Scott Ocamb" <so****@hotmail.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
I want to write a simple class that loads a requested url and reports
success or failure. I plan to use this to monitor web sites on the web.

I would like to implement the class in a windows form and a service.

Any help would be appreciated.

scott

Nov 18 '05 #2
I came across an example that is much better in this scenario. The idea came
from Duncan Mackenzie's "Digital Grandma" article in this months MSDN mag.
Jared

Shared Sub Main()
Console.WriteLine("Google: " & CheckSite("http://www.google.com"))
Console.WriteLine("MSN: " & CheckSite("http://www.msn.com"))
Console.WriteLine("Bad URL: " &
CheckSite("http://www.thisisabadurl.com"))
Console.ReadLine()
End Sub

Shared Function CheckSite(ByVal URL As String) As String
Try
Dim Request As Net.HttpWebRequest = _
Net.WebRequest.Create(URL)
Return CType(Request.GetResponse,
Net.HttpWebResponse).StatusCode.ToString
Catch webex As System.Net.WebException
Return webex.Status.ToString
Catch ex As Exception
Throw
End Try
End Function
"Scott Ocamb" <so****@hotmail.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
I want to write a simple class that loads a requested url and reports
success or failure. I plan to use this to monitor web sites on the web.

I would like to implement the class in a windows form and a service.

Any help would be appreciated.

scott


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: brianbender | last post by:
I am trying to load and unload assemblies dynamically and call methods and properties when loaded into an Appdomain I can load assemblies all day in the current AppDomain without references and...
4
by: James Wong | last post by:
Hi everybody, I'm developing a web service using VB.NET which calls a web form to let user input something. In web service, I use Server.Execute ("WebForm.aspx") to load and execute the web...
11
by: Wolfgang Kaml | last post by:
I am not sure if this is more of an expert question, but I am sure that they are out there. I'd like to setup a general application or bin directory on my Win2003.Net Server that will hold some...
1
by: Jeffrey Kelso | last post by:
I am having an issue where doing a PostBack in ASP.NET is losing the form information. This is happening in a NLB environment with two servers using Application Center When a user selects an...
11
by: Jason | last post by:
Hi I have a "problem" i have got a ASP.NET application. in this application i have included logging. in the logging i have logged how many seconds it takes for this application to fully load....
22
by: EP | last post by:
When running my asp.net hosting service (asp.net without IIS), on server 2003 with IIS not installed, I get the following when trying to process a request. "System.DllNotFoundException: Unable to...
3
by: dercon | last post by:
I'm attempting to dynamically load an assembly from a windows service. However, i'm having problems when the service runs... he is the line of code that causes the error: dim loAssembly as...
2
by: Andy Hunt | last post by:
Hi, I am having a problem with SQLXML Bulk Load inside of a web service ( also inside of a basic aspx page). I have a WebMethod in a web service that makes a call to bulk load. This works...
5
by: Med | last post by:
Hi, Initial load of my pre-compiled ASP.NET app takes more than 50 seconds to load after site has been idle for a while. Then it become fairly fast. Followings are my app/hardware configs: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
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...
0
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.