c#geckofx文件流下载
2016-06-29 10:41
489 查看
备注:内容仅提供参考。
⒈添加引用:using Gecko;
⒉然后根据自己的情况在某个方法内添加事件:
⒊再声明方法:
⒈添加引用:using Gecko;
⒉然后根据自己的情况在某个方法内添加事件:
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(); } } }
相关文章推荐
- C#遍历文件夹及其子目录的完整实现方法
- C# 验证数字
- C#简单遍历指定文件夹中所有文件的方法
- c#读取Excel的第一个Sheet表
- C#如何读取Excel文件
- C#基础一
- C#中一些常用的加密和哈希处理
- C#个人总结2——类和对象
- C#使用tesseract3.02识别验证码模拟登录
- c#中Invoke使用方法(线程间操作无效: 从不是创建控件的线程访问它。那么创建它的线程是哪个线程?)
- C#.NET 定时器类及使用方法
- LCS算法找出两个字符串最长公共子串(C#实现)
- c# PictureBox 的图像上使用鼠标画矩形框
- 单例(C#版)
- C#执行存储过程
- C# 互操作性入门系列(三):平台调用中的数据封送处理
- C#学习心得与自我反思
- C#之结构Struct
- C#实现上传图片
- 定义C#的类