0

I've run in the following problem:

I've developed a C# application which in one part uses the webbrowser control.

Under certain circumstances the webbrowser control opens a Window titled "File Download - Security Warning".

My question is: How can I find this Window and close it?

I've stumbled upon the FINWINDOW and FINDWINDOWEX functions of the API, but I don't get it.

Anyone who could help?

venerik
  • 5,766
  • 2
  • 33
  • 43
  • Are you sure you want to close the window? I'd investigate the reason the window pops up and solve that problem instead. – venerik Jun 05 '13 at 19:42
  • I've investigated in this direction too. It's just the response of a javascript within the website of the type json/application which initiates the warning message. It's just a problem of IE not handling this mime type correctly. – MrDoubleU Jun 05 '13 at 19:52
  • are you sure that the contenttype is being set correctly?? [JSON](http://stackoverflow.com/questions/267546/correct-http-header-for-json-file) – Paul Farry Jun 05 '13 at 19:54

2 Answers2

0

If you are downloading via a WebControl from within your application you will have other issues. Maybe you could intercept or prevent the download from the webcontrol and instead use HTTPClient or HTTPWebRequest to download the file and thus bypass the WebControl downloading.

You could always "try" to close the dialog, but that may not be the nicest experience for the user it may also not be possible. You can find lots of examples for P/Invoke for FindWindow

Paul Farry
  • 4,730
  • 2
  • 35
  • 61
  • Thank you for your answer. In this case the user must login to a website, so using a HTTPClient or HTTPWebRequest is not a way I can go, because I would need to read out his login data, which I don't want to. – MrDoubleU Jun 05 '13 at 19:50
  • Is there a way you can set a Token in the WebBrowser, extract that after they have logged in, and then use this in your WebRequest to bypass. (This of course is based on you having control of the Server) – Paul Farry Jun 05 '13 at 19:52
0

Could you please try the below snippet. Please mark the answer if its useful. Import the System.Diagnostics namespace

foreach (Process item in Process.GetProcesses())
{
  if (item.MainWindowTitle.Equals("File Download - Security Warning"))
     {
       item.CloseMainWindow();           
     }
}
Vimal CK
  • 3,543
  • 1
  • 26
  • 47
  • I've tried out your solution, but it doesn't work, because it only finds the processes with all the main window title. What I need is to find the title of childwindow of the current process. – MrDoubleU Jun 05 '13 at 22:06