Basics: I have a Windows .NET Form application with an embedded WebBrowser control. It is triggering a download which opens the "Save Download" dialog. I would like to click on the "Save" button automagically.
I found this other StackOverflow question: Press save button of "File download dialog" of internet explorer via c# but it has no real answers.
The code I have so far doesn't reliably work when deployed to the actual workstation. Running it in debug/from Visual Studio, it works fine. On actual workstations, sometimes the Save button "highlights" or depresses like it's clicked, but nothing actually happens.
Here be the code:
Dim dialogHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "File Download")
Dim buttonTitle = "&Save"
Dim dialogButtonHandle = FindWindowEx(dialogHandle, IntPtr.Zero, "Button", buttonTitle)
SendMessage(dialogButtonHandle, BM_SETSTATE, 0, 0)
SendMessage(dialogButton, BM_CLICK, 1, 0)
SendMessage(dialogButtonHandle, BM_SETSTATE, 1, 0)
I have no idea if this is even the totally 100% correct way of clicking buttons in other windows, but it seems to somewhat work. Maybe I'm sending SendMessage's too fast? Too slow? Should I be using SendMessage with BM_CLICK, etc. or some other actions? I feel like I'm 90% of the way there.. any help would be appreciated.