views:

26

answers:

3

I have an ASP.NET web form that reads a file and writes some data to a database. I need to run this process on a scheduled basis.

Currently, I have a scheduled task that calls a batch file. The batch file then opens Internet Explorer and navigates to the URL and the process is fired. There is another scheduled batch file that closes Internet Explorer.

Surely, there is a more elegant way to do this.

+1  A: 

Do you have access to change the web site? Probably the most elegant solution would be to abstract the functionality behind the web form into its own class and have the web form and a web service call it. Then create a client application (windows service or scheduled console app... I recommend the latter because it's easier to debug and maintain over time) that hits the web service. The site can still be hit manually if/when needed.

If the answer to my first question, however, is "no" then I would suggest a scheduled client app that just builds a web request and fires it off. Does anything more need to be done other than just loading the page in order to initiate the process?

David
Web Services are usually bad with [binary file]/[ascii with specials]. You'll end up encoding everything in base64.
h3xStream
Yes, I have full control over the website.
mmcglynn
@h3xStream: Maybe I interpreted the request incorrectly. It sounded to me like it's all done on the server side and the web form just "tells it to go."
David
@David you're probably right
h3xStream
+1  A: 

If you just fetch a page to start the process, you could do that with powershell instead of IE:

$webclient = New-Object System.Net.WebClient
$response = $webclient.DownloadData("http://www.stackoverflow.com/")

If you need to verify some return value, you can get it like this:

$encoding = New-Object System.Text.utf8Encoding
$returnvalue = $encoding.GetString($response)
Per-Frode Pedersen
A: 

If you have cygwin or wget, you can just schedule a call like

wget http://URL/whatever?getparams

This will just complete the request and close by itself. More elegant than trying to use IE, but not as programming-intensive as the others.

palswim