I need to navigate within a web based program in our company and download files. (pdf, zip, doc ) anything that may be stored under a specific part number on our system.
I am able to: Open the page, type in a login and password, navigate through to various pages, and locate the link to a file I want, and even click it programatically. But im stuck when the "File Download" popup comes up and asks if I want to "Open, Save or Cancel". This is where I need help.
I've accomplised everthing so far by: 1) reading lots of posts on ni forums (thank you to the contributors of this forum!!) and ....
2) using: An ActiveX WebBrowser object, looking at "IWebBrowser2" methods, retriving the page document and elements using "IHTMLDocument2.All method". Poking around using IHTMLElementCollection and IHTMLElement methods. In IHTMLElement you can look at properties of page elements and once you find the one you want, you can use the "IHTMLElement.Click" event to click the link.
This is all grat now I have a popup box that asks me if i want to "Open, Save, or Cancel". So I need to figure out how to :
1) Click Save, programatically
2) Point the file to a path of my choosing.
As a suggestion, I would try using the .NET browser control instead of the ActiveX one. There are lots more properties/methods that are exposed and using the 'register for event callback' you can pick up on things like mouse click events or the URL changing.
It may be that you can get the link URL from the click and then use that to initiate a download, or once you have the file open in the browser window you might be able to initiate a save that way.
It might be worth a look at, anyway!
So here is a VI I didn't know if it would work because I didn't intend on using it this way but it apparently does which is a surprise.
It uses DataSocket to request a URL text, then saves it to a file. I used this in the past to save things like an image, put in the URL and then the File name and it would save it to a file or directory. So I tried it on a html page and it worked as well. It uses some OpenG to make a directory if one doesn't exist, and to remove the error 7 if the destination file doesn't exist yet.
I've found a site that speaks to this very issue of clicking the buttons programatically, but its for VB6 ( so im working through trying to translate over)
I've read alot of posts that suggest using [My.Computer.Network.DownloadFile (address) ] or similar alrady made vi's that require the URL address. They suggest searching through the elements, if you dont have the URL, and once you find the target element, extract the url.
example line from one of the pages ( ive changed some values incase it exposes something in our system, but you get the idea)
I'll post more as I learn more. I might need to take Sam_Sharp's idea and use .NETcontrol rather than the ActiveX. But I'm thinking I will still run into the same hurdle eventually when I try to download the file.