Search code examples
c#.netwindows-servicesautomationwatin

Open web page, login and then download file


Task: I have to open a web page (https), enter username and password, click some links to get to a desired page and then download all files (pdf) to a shared folder on our internal network.

I'd like to do this with windows service which would run once every night. What is the best way to do this?

I tried watin, it is pretty easy to fire up a browser, navigate to my web page, enter username and password, click some links, ... but then I don't know how to automatically download a file. As I understand, you can't do this without user interaction. Also - I don't know if it is even possible to run watin from windows service; where would the browser instance be running?

Any other ideas?


Solution

  • You can do the following:

    1. Save the page with entered username and password in it
    2. Write a small C# client program that will run a local server which will submit the page file
    3. Gaining the session, submit also a previously saved URL to the PDF downloadable page
    4. In the same app add the client downloading part that downloads all the files existing under that session.

    Writing such a program wont take more than an hour from your time.

    Advantages:

    1. You can change over time, the way you like it to perform
    2. You have full control on your client part