// From Timothy N in https://bitbucket.org/geckofx/geckofx-29.0/issue/34/how-to-download-files-using-this-engine static void LauncherDialog_Download(IWin32Window owner, object sender, LauncherDialogEvent e) { uint flags = (uint)nsIWebBrowserPersistConsts.PERSIST_FLAGS_NO_CONVERSION | (uint)nsIWebBrowserPersistConsts.PERSIST_FLAGS_REPLACE_EXISTING_FILES | (uint)nsIWebBrowserPersistConsts.PERSIST_FLAGS_BYPASS_CACHE; SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = e.Filename; if (sfd.ShowDialog(owner) == DialogResult.OK) { // the part that do the download, may be used for automation, or when the source URI is known, or after a parse of the dom : string url = e.Url; //url to download string fullpath = sfd.FileName; //destination file absolute path nsIWebBrowserPersist persist = Xpcom.GetService <nsIWebBrowserPersist>("@mozilla.org/embedding/browser/nsWebBrowserPersist;1"); nsIURI source = IOService.CreateNsIUri(url); nsIURI dest = IOService.CreateNsIUri(new Uri(fullpath).AbsoluteUri); persist.SetPersistFlagsAttribute(flags); persist.SaveURI(source, null, null, null, null, (nsISupports)dest, null); // file is saved - asynchronous call // need to try to have a temp name while the file is downloaded eg filename.ext.geckodownload (one of the SaveURI option) } }
public static nsIWebBrowserPersist GetProxy(Mono.WebBrowser.IWebBrowser control, nsIWebBrowserPersist obj) { object o = Base.GetProxyForObject(control, typeof(nsIWebBrowserPersist).GUID, obj); return(o as nsIWebBrowserPersist); }
public static nsIWebBrowserPersist GetProxy (Mono.WebBrowser.IWebBrowser control, nsIWebBrowserPersist obj) { object o = Base.GetProxyForObject (control, typeof(nsIWebBrowserPersist).GUID, obj); return o as nsIWebBrowserPersist; }