c#geckofx文件流下载
生活随笔
收集整理的這篇文章主要介紹了
c#geckofx文件流下载
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
備注:內(nèi)容僅提供參考。
⒈添加引用:using Gecko;
⒉然后根據(jù)自己的情況在某個方法內(nèi)添加事件:
LauncherDialog.Download += new EventHandler<LauncherDialogEvent>(OnDownloadFile);⒊再聲明方法:
private void OnDownloadFile(object sender, LauncherDialogEvent e){nsILocalFile objTarget = Xpcom.CreateInstance<nsILocalFile>("@mozilla.org/file/local;1");using (nsAString tmp = new nsAString(@Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\temp.tmp")){objTarget.InitWithPath(tmp);}//Save file dialog Stream myStream;System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();saveFileDialog1.Filter = "All files (*.*)|*.*";saveFileDialog1.FilterIndex = 2;saveFileDialog1.RestoreDirectory = true;saveFileDialog1.FileName = e.Filename;if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK){if ((myStream = saveFileDialog1.OpenFile()) != null){nsIURI source = IOService.CreateNsIUri(e.Url);nsIURI dest = IOService.CreateNsIUri(new Uri(@saveFileDialog1.FileName).AbsoluteUri);nsAStringBase t = (nsAStringBase)new nsAString(System.IO.Path.GetFileName(@saveFileDialog1.FileName));nsIWebBrowserPersist persist = Xpcom.CreateInstance<nsIWebBrowserPersist>("@mozilla.org/embedding/browser/nsWebBrowserPersist;1");persist.SaveURI(source, null, null, null, null, (nsISupports)dest, null);nsIDownloadManager DownloadMan = null;DownloadMan = Xpcom.CreateInstance<nsIDownloadManager>("@mozilla.org/download-manager;1");nsIDownload download = DownloadMan.AddDownload(0, source, dest, t, e.Mime, 0, null, (nsICancelable)persist, false);if (download != null){persist.SetPersistFlagsAttribute(2 | 32 | 16384);persist.SetProgressListenerAttribute((nsIWebProgressListener)download);persist.SaveURI(source, null, null, null, null, (nsISupports)dest, null);}myStream.Close();}}}?
轉(zhuǎn)載于:https://www.cnblogs.com/RedSky/p/5626006.html
總結(jié)
以上是生活随笔為你收集整理的c#geckofx文件流下载的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML5 Web 存储(localSt
- 下一篇: 各类排序算法实现(亲测)