Download Excel file from URL - vb.net

Background
I am attempting to automate the downloading of an Excel file given a URL. I know how to do this, and realize there are many examples for how to do this using either the webbrowser or webclient control however my situation is somewhat different.
Problem
If I simply paste the URL into a normal browser, it will result in asking me to save / open the file like normal. When using the same URL with either the web browser or web client controls, it results in no file. I believe this is because the URL is simply a SharePoint link, that sends a request to get the file, but is not the actual file itself.
This can be done for security reasons or whatever the case is but I was wondering if anyone has ever found a way around this?
Perhaps a way to even just emulate the browser, then emulate clicking save?
The URL for the Excel file does NOT end in .xlsx, it ends in something like:
webclient/zhZZXYRyAaLUgD?TC_file=redirs/viewdataset
which is why I think the server simply processes the request and then provides the browser the file.
I am attempting to do this in VB.NET but VBA or VB answers seem like they should work as well.
Fiddler Results

I seemed to find an easy way to solve my problem. After downloading my file within Internet Explorer, and then viewing my recent downloads, IE has an option if you right click and select "Copy Download Link". This puts the true download URL in the clipboard and actually works using the My.computer.downloadfile method.

Related

webbrowser control shows a save as dialog instead of displaying a local .mhtml page

This one has me scratching my head.
We have a "Previewer" which hosts a WebBrowser control.
When this "Previewer" is used to "preview" a Word document or Excel Spreadsheet I use some code to convert the document to a .mhtml file. I then tell the WebBrowser to navigate to that.
This works fine on many machines but not all. On some machines, instead of "navigating" to the mhtml and displaying it in the WebBrowser control, the WebBrowser control takes it upon itself to present a "Save As" dialog, asking the user to save the .mhtml file to their PC.
What is going on here, and how do I stop it?
Thanks
An example of the sort of file I try to navigate to:
"file://127.0.0.1/C$/Users/blahblahblahhere/AppData/Local/furthersubfoldershere/637183327673490444_Document1_486951.mhtml"
All I'm doing is
oWB.Navigate(....)
Ok.... this may also be relevant. This happens when a user is using an add-in we wrote in Outlook 365.... So the WebBrowser control is hosted in our Add-in in one of the forms it pops up as the user is doing their thing in Outlook.
Well, I still don't know why it does this for an .mhtml file, but I found that converting it to .html instead actually works. I was reluctant to do that as a Word Document or an Excel Spreadsheet converted to HTML might produce an .HTML file with lots of associated files, e.g. for images. But while it does indeed do that, as it turns out it still works quite happily in the WebBrowser control. And without popping up that "save" dialog.
If you must use MHTML I have no solution for you, but if HTML is "good enough" for you, well, that's how I fixed it for myself.

Simulate drag & drop file to website in VBA

I have an Access database that uses VBA code to generate a GPX map file. That works fine. I then want the contents of the GPX file to be displayed on a website, https://mapy.cz
The method that the site authors intend is for users to open the site, then manually drag and drop GPX files onto the site, at which point the contents are read in and displayed by the website. This also works fine.
What I want to do is NOT require my database user to open a browser, locate the file and drag it onto the browser by hand. I want my VBA code to not only create this GPX file, but also open the user's default browser, direct it to this mapping site (all this also works okay), but then SIMULATE or FORCE the drag and drop action FROM MY VBA CODE. That is the part that on which I'm floundering. I've looked up things like using VBA's IE.Document object, and it seems to me that it should be in there somewhere, but I can't find anything that makes sense to me.
I've done similar things in the past, with SendKeys to simulate the user typing, and AutoIT to code-control a running DOS application, including reading the programs responses from the DOS screen and forcing in commands, all from VBA. It seems to me that this should be possible, and not even all that uncommon a requirement, but I've not located anything helpful in all my searching, and I've done a lot. Maybe I'm simply phrasing my searches wrong, but at this point, I'm just flat stuck.

"Choose File" not work for firefox while it works for chrome

I am using robotframework ,selenium2Library, selenium2 and python27 to test web program. It need to upload a file in my web program. I use Choose File to give file path value to input filed. But it is not work for firefox and it works fine in chrome. When I upload file manually in firefox, it works. It is a register page. Javascript code told that file upload field is empty when the form is trying to submit, since selenium seems did not give the file path to the value of file upload field. And other input fields all have been input values, no matter fields before this file upload filed nor those fields after it. Does anyone know how to solve this problem or is there any alternative solutions?
I've had success having selenium type the file path into the webpage directly. It works most of the time, but the site I use it on is being constantly updated and one week you can type a file path, the next week you can't, the following week you can again.
I say this as a precaution that this may not be the ultimate solution, but there are instances where it works. Your particular case may be able to use this method.
driver.find_element_by_name("FILE_UPLOAD_ELEMENT_NAME").send_keys(os.path.expanduser("~/PATH_TO_FILE"))
Feel free to find element by any other characteristic and replace the all caps parts be appropriate for your use.

ASP Response.AddHeader Content-Disposition not working for Acrobat

I have a script that generates a temporary PDF file, binary-streams it to the client, then deletes it.
If you click on "Save Page As" in the browser File menu, it wants to save the correct file name that I specified through Content-Disposition.
However, if you click on the Save button in the Acrobat reader or Acrobat Pro, it wants to save the name of the script file, replacing ".asp" with ".pdf". It's like Acrobat completely ignores "Content-Disposition"
It's important that I don't use a static URL, but instead use a Dynamic script to generate the PDF, so that I can delete it immediately upon closing the stream. Otherwise, I can't know when the client is finished downloading.
Is there a solution to this? I've seen several threads, but none with an answer.
You can use a URL rewriter to point a "static" path to your dynamic script.
See this blog post on classic asp redirection.
So, you can have a link like:
http://www.example.com/12_234_file.pdf
Redirect to:
http://www.example.com/dynamic.asp?id=12&id2=234
The client will see the URL before it was re-written and should use that.

rewrite URL to affect "save as" filename

My application is in JSP/Struts and running on WebSphere. I don't have access to the server /really/ so I'm trying to do all this from within the app itself (Struts actions & config, JSP, etc).
I have a page that displays links for PDF documents that the user might want to look at. When they click on the link, it is forwarded to the 'document view' STRUTS action which performs the work to retrieve the PDF from the back-end system and then displays the PDF in the browser window. This all works fine.
The users have asked to have the file name of the document be customized for each document when they go to File->Save As... but right now the browser wants to try to name the document after the name of my Struts action. Example: "documentView.pdf"
I have the filename I want to use forwarded to the STRUTS action and I tried using the "Content-Disposition" header to set this, but haven't been able to get it to work. Actually it works great if I use "attachment; filename="myfilename" " but then it FORCES the "Save As..." dialog straight away, which I don't want either.
I want to be able to look at the PDF inline in the browser window and save it with a custom filename if I so choose.
I have read that this might be possible to do with URL rewriting but I'm having trouble sorting out how this technique might work.
Any ideas will be greatly appreciated.
Change the "attachment" part of the Content-Disposition to "inline".
Browser support for Content-Disposition is flaky.
Before it was supported, you used to be able to get the browser to do the right thing by putting a superfluous key/value at the end of the URL. Like:
http://example.com/getPDF?id=123213&filename=mydoc.pdf
Some browsers picked up the last bit of the URL as the filename. Not sure if that still works.