Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1562 | Anzahl registrierter User: 1893 | Besucher online: 302
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Firefox Utilities


Autor: Jan Welker
Sprache: C#
Bewertung:
4.38 (3 votes)
Anzahl der Aufrufe: 7230
  
Kick it on dotnet-kicks.de  

Beschreibung:

Die Klasse stellt einige Methoden bereit die den Umgang mit dem Firefox aus der eigenen Anwendung erleichtern sollen.
Eine genaue Beschreibung der Methoden entnehmen Sie bitte den XML Kommentaren.
Folgende Methoden sind implementiert:

IsFirefoxAvailable()
OpenFirefox()
OpenFirefox(string url)
OpenFirefoxInSaveMode()
OpenFirefoxInNewWindow(string url)
OpenFirefoxInNewTab(string url)
OpenMozillaWebsite()

getestet wurde die Klasse mit Firefox V 2.0.0.4

Benötigte Namespaces:
using System;
using System.Diagnostics;
using System.IO;


Abgelegt unter: Browser, Firefox.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class FirefoxUtilities
{
    private string firefoxPath;

    /// <summary>
    /// Initializes a new instance of the <see cref="FirefoxUtilities"/> class.
    /// </summary>
    public FirefoxUtilities()
    {
        firefoxPath =
            string.Format(@"{0}\Mozilla Firefox\firefox.exe",
                          Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
    }

    /// <summary>
    /// Open Firefox if Firefox is available
    /// </summary>
    /// <param name="arguments">the url</param>
    private void Open(string arguments)
    {
        if (!IsFirefoxAvailable())
            throw new Exception("Firefox is not installed.");
        else
            Process.Start(firefoxPath, arguments);
    }

    /// <summary>
    /// Determines whether [is firefox available].
    /// </summary>
    /// <returns>
    /// 	<c>true</c> if [is firefox available]; otherwise, <c>false</c>.
    /// </returns>
    public bool IsFirefoxAvailable()
    {
        FileInfo fiFirefox = new FileInfo(firefoxPath);
        return fiFirefox.Exists;
    }

    /// <summary>
    /// Opens the firefox.
    /// </summary>
    public void OpenFirefox()
    {
        Open(string.Empty);
    }

    /// <summary>
    /// Opens the firefox with a specific url.
    /// </summary>
    /// <param name="url">the url</param>
    public void OpenFirefox(string url)
    {
        Open(url);
    }

    /// <summary>
    /// Opens the firefox in save mode.
    /// </summary>
    public void OpenFirefoxInSaveMode()
    {
        Open("-safe-mode");
    }

    /// <summary>
    /// Opens the firefox in a new window.
    /// </summary>
    /// <param name="url">the url</param>
    public void OpenFirefoxInNewWindow(string url)
    {
        Open(string.Format("-new-window {0}", url));
    }

    /// <summary>
    /// Opens the firefox in a new tab.
    /// </summary>
    /// <param name="url">the url</param>
    public void OpenFirefoxInNewTab(string url)
    {
        Open(string.Format("-new-tab {0}", url));
    }

    /// <summary>
    /// Opens the mozilla website.
    /// </summary>
    public void OpenMozillaWebsite()
    {
        Process.Start("http://www.mozilla-europe.org");
    }
}
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)

Gregori schrieb am:  27.06.2007 19:32:55

Es wurde der Pfad zur Anwendung fest einprogrammiert. Kann man nicht im grossen Umfang anwende. Eine Idee wäre die Verwendung der Regestry:
- HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 2.0.0.4\bin
- HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox\2.0.0.4 (en-US)\Main

Aber ist natürlich nicht wirklich Systemunabhängig...

Gruss,
Gregor


schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.