How do I handle file downloads in GeckoFX?

喜你入骨 提交于 2019-12-22 20:00:10

问题


I am using the latest GeckoFX 18 (hindlemail's fork) and have tried hard to achieve this simple method : Handle file downloads.

I want to know if there is a file download happening in the GeckoWebBrowser. There is no file download event, and even worse : clicking a link that leads to a file download doesn't trigger /any/ event. It just doesn't do nothing. No download dialog, no save file dialog, no url, no nothing.

Is there a way I can handle file downloads ?


回答1:


By using hindlemail's fork of geckofx you will have to handle LauncherDialog.Download event. This event has several parameters like url, filename, etc.

LauncherDialog.Download += LauncherDialog_Download;
////
void LauncherDialog_Download(object sender, LauncherDialogEvent e)
{
    string filename = e.Filename; //do something with filename
    string url = e.Url; //use webclient to download file from this url
}

Even with this you will not be able to download files from secure sites like dropbox or facebook but it will download something, better than nothing. I don't know much about xul so I also has a hard time downloading files.

I tried this too:

void LauncherDialog_Download(object sender, LauncherDialogEvent e)
{
    WebBrowser ie = new WebBrowser();
    ie.Navigate(e.Url);
}

It will show Internet Explorer download file dialog if file can be downloaded that way. Probably cause of request headers or something. I also used Fiddler to find out what headers Firefox sends to server but I found nothing useful.



来源:https://stackoverflow.com/questions/16019107/how-do-i-handle-file-downloads-in-geckofx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!