Showing results for 
Search instead for 
Did you mean: 

Programatically "Save As" after navigating to a web page file link

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 can't point to the link of the file because I wouldnt know its path (especially not at runtime), also the program runs javascript so I cant inspect the element manually and look at the address of the link.  So I'm pretty sure I need to navigate to the link through the front end like I have been doing.


 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.



0 Kudos
Message 1 of 6

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!

LabVIEW Champion, CLA, CLED, CTD
0 Kudos
Message 2 of 6

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.

0 Kudos
Message 3 of 6

You can also use the HTTP Client GET VI as well 🙂


(It has the bonus that it can do HTTP AUTH to authenticate yourself)

LabVIEW Champion, CLA, CLED, CTD
Message 4 of 6



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)

Part I

Part 2


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. 


This would work great, but I looked into the elements and it doesnt seem to be using a direct URL to get the file , rather it uses javascript:openfile().



example line from one of the pages ( ive changed some values incase it exposes something in our system, but you get the idea)


<A class=image_link tabIndex=-1 onclick="javascript&colon;openFile('', '6159','123456789','1','123456788','185227304','','426286',' ',false,false);" href="javascript&colon;noaction();"></A>


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.

0 Kudos
Message 5 of 6

The openFile function is probably defined in the javascript code / scripts somewhere (it's not a native JS function) - you might be able to get some information about the URL by looking at the source for the function. You might might be that it calls a server script that loads the file. Using the javascript/developer tools in your browser might help you to figure out what's going on.


LabVIEW Champion, CLA, CLED, CTD
0 Kudos
Message 6 of 6