0

我在我的 Visual Basic 应用程序中使用 gecko15 和 mozilla xul15 作为 Web 浏览器

有人知道我如何处理下载吗?

因为,当我单击要从该浏览器下载的文件时,什么也没有发生。

非常感谢您的帮助。

4

3 回答 3

0

另外:@Form 加载事件:添加:AddHandler Gecko.LauncherDialog.Download, AddressOf LauncherDialog_Download

然后 Private Sub LauncherDialog_Download(ByVal sender As Object, ByVal e As Gecko.LauncherDialogEvent) e.cancel() try catch ex as exception finally e.Navigate(Nothing) '防止异常 DM 行为 end try End Sub

希望有帮助,

于 2014-01-01T14:32:27.990 回答
0

这是我们所有人都头疼的问题,不能让用户在嵌入式(vb net)壁虎浏览器中下载文件。匿名天才“Kixpsider(我的朋友万岁)”结束了这个麻烦。请以清晰的格式遵循以下代码:

    Dim objTarget As Gecko.nsILocalFile = Gecko.Xpcom.CreateInstance(Of Gecko.nsILocalFile)("@mozilla.org/file/local;1")
    Dim tmp_Loc As String = Application.StartupPath & "\data"
    Dim sx As Object = Nothing
    Dim fx As String = ""
    Dim saveBox As New SaveFileDialog
    Dim win As Object = Gecko.Xpcom.GetService(Of Gecko.nsIWindowWatcher)("@mozilla.org/embedcomp/window-watcher;1")

    'win.OpenWindow(Nothing, "chrome://mozapps/content/downloads/downloads.xul", "Downloads", "chrome,resizable=yes,hide", Nothing)

    Using tmp As New Gecko.nsAString(tmp_Loc)
        objTarget.InitWithPath(tmp)
    End Using

    If e.Filename.Contains(".") Then
        sx = Strings.Split(e.Filename, ".")
        fx = sx(sx.Length - 1).ToUpper & " File (*." & sx(sx.Length - 1) & ")|*." & sx(sx.Length - 1)
    Else
        fx = "File (*.*)|*.*"
    End If

    savebox.Filter = fx '"HTML File (*.html)|*.html"
    savebox.Title = "Save File:"
    savebox.FileName = e.Filename
    If saveBox.ShowDialog <> System.Windows.Forms.DialogResult.OK And String.IsNullOrEmpty(saveBox.FileName) Then
        Exit Sub
    End If
    Dim source As Gecko.nsIURI = Gecko.IOService.CreateNsIUri(New Uri(e.Url).AbsoluteUri)
    Dim dest As Gecko.nsIURI = Gecko.IOService.CreateNsIUri(New Uri(saveBox.FileName).AbsoluteUri)
    Dim t As Gecko.nsAStringBase = DirectCast(New Gecko.nsAString(System.IO.Path.GetFileName(saveBox.FileName)), Gecko.nsAStringBase)

    Dim persist As Gecko.nsIWebBrowserPersist = Gecko.Xpcom.CreateInstance(Of Gecko.nsIWebBrowserPersist)("@mozilla.org/embedding/browser/nsWebBrowserPersist;1")
    Dim DownloadMan As Gecko.nsIDownloadManager = Gecko.Xpcom.CreateInstance(Of Gecko.nsIDownloadManager)("@mozilla.org/download-manager;1")
    Dim downloadX As Gecko.nsIDownload = DownloadMan.AddDownload(0, source, dest, t, e.Mime, 0, Nothing, DirectCast(persist, Gecko.nsICancelable), False)

    If (downloadX IsNot Nothing) Then
        persist.SetPersistFlagsAttribute(2 Or 32 Or 16384)
        persist.SetProgressListenerAttribute(DirectCast(downloadX, Gecko.nsIWebProgressListener))
        persist.SaveURI(source, Nothing, Nothing, Nothing, Nothing, DirectCast(dest, Gecko.nsISupports), Nothing)
    End If
于 2016-01-30T10:21:58.170 回答
-1

'注:去掉“'”

' Dim P As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\\tmp" ' If Not System.IO.Directory.Exists(P) Then System.IO.Directory.CreateDirectory(P)

                    '                        Dim objTarget As nsILocalFile = Xpcom.CreateInstance(Of nsILocalFile)("@mozilla.org/file/local;1")
                    '                        Dim tmp_Loc As String = P & "\tmpdload"
                    '                        Using tmp As New nsAString(tmp_Loc)
                    ' objTarget.InitWithPath(tmp)
                    ' End Using

                    ' If e.Filename.Contains(".") Then
                    'S = Strings.Split(e.Filename, ".")
                    'F = S(S.Length - 1).ToUpper & " File (*." & S(S.Length - 1) & ")|*." & S(S.Length - 1)
                    'Else
                    '    F = "File (*.*)|*.*"
                    'End If

                    '    savebox.Filter = F '"HTML File (*.html)|*.html"
                    '    savebox.Title = "Save File:"
                    '    savebox.FileName = e.Filename
                    '    If savebox.ShowDialog = System.Windows.Forms.DialogResult.OK And Not String.IsNullOrEmpty(savebox.FileName) Then
                    ' Dim source As nsIURI = IOService.CreateNsIUri(New Uri(e.Url).AbsoluteUri)
                    ' Dim dest As nsIURI = IOService.CreateNsIUri(New Uri(savebox.FileName).AbsoluteUri)
                    ' Dim t As nsAStringBase = DirectCast(New nsAString(System.IO.Path.GetFileName(savebox.FileName)), nsAStringBase)
                    '
                    '                       Dim persist As nsIWebBrowserPersist = Xpcom.CreateInstance(Of nsIWebBrowserPersist)("@mozilla.org/embedding/browser/nsWebBrowserPersist;1")
                    '                       Dim DownloadMan As nsIDownloadManager = Xpcom.CreateInstance(Of nsIDownloadManager)("@mozilla.org/download-manager;1")
                    '                       Dim downloadX As nsIDownload = DownloadMan.AddDownload(0, source, dest, t, e.Mime, 0, Nothing, DirectCast(persist, nsICancelable), False) '

                    '                        If (downloadX IsNot Nothing) Then
                    'persist.SetPersistFlagsAttribute(2 Or 32 Or 16384)
                    'persist.SetProgressListenerAttribute(DirectCast(downloadX, nsIWebProgressListener))
                    'persist.SaveURI(source, Nothing, Nothing, Nothing, Nothing, DirectCast(dest, nsISupports), Nothing)

'显示 FF 下载管理器:'Dim win = Xpcom.GetService(Of nsIWindowWatcher)("@mozilla.org/embedcomp/window-watcher;1") ' win.OpenWindow(Nothing, "chrome://mozapps/content /downloads/downloads.xul", "下载", "chrome,resizable=yes,hide", 没有)

于 2014-01-01T14:29:02.647 回答