html pagina openen met OpenFileDialog

Status
Niet open voor verdere reacties.

kayhup

Gebruiker
Lid geworden
24 mei 2007
Berichten
126
Ik wil met een OpenFileDialog een html pagina laten openen in een webbrowser... weet iemand hoe ik dit moet doen... Ik heb al op google gezocht...maar zonder resultaat...


P.S. in heb Visual Basic Express Editon 2005
 
Heb de oplossing voor jou probleempje:

Code:
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Dim ofd As New OpenFileDialog
        ofd.Filter = "HTML-Files (*.html)|.html|HTM-Files (*.htm)|*.htm"
        ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Process.Start(ofd.FileName)
        End If
    End Sub
 
Heb de oplossing voor jou probleempje:

Code:
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Dim ofd As New OpenFileDialog
        ofd.Filter = "HTML-Files (*.html)|.html|HTM-Files (*.htm)|*.htm"
        ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Process.Start(ofd.FileName)
        End If
    End Sub
Hij werkt wel, maaar hij moet hem openen in MIJN webbrowser....
 
Ik wil met een OpenFileDialog een html pagina laten openen in een webbrowser

Je zei voor 'een' webbrowser, dus dacht ik aan IE of FF :rolleyes:,
maar geen enkel probleem, hier heb je al de code voor UW webbrowser :D

Code:
        Dim ofd As New OpenFileDialog
        ofd.Filter = "HTML-Files (*.html)|.html|HTM-Files (*.htm)|*.htm"
        ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim adres As New Uri(ofd.FileName)
            webBrowser.Url = adres               'Dit is een standaard webbrowser die in de toolbox zit
        End If
 
Je zei voor 'een' webbrowser, dus dacht ik aan IE of FF :rolleyes:,
maar geen enkel probleem, hier heb je al de code voor UW webbrowser :D

Code:
        Dim ofd As New OpenFileDialog
        ofd.Filter = "HTML-Files (*.html)|.html|HTM-Files (*.htm)|*.htm"
        ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim adres As New Uri(ofd.FileName)
            webBrowser.Url = adres               'Dit is een standaard webbrowser die in de toolbox zit
        End If

Heel erg bedankt:D Weet je ook heel toevallig hoe je een pagina kan opslaan...??
 
Laatst bewerkt:
Maar natuurlijk :D:

Code:
        Dim client As New System.Net.WebClient
        Dim sfd As New SaveFileDialog
        sfd.Filter = "All Files (*.*)|*.*"
        sfd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        sfd.FileName = "index.html"
        If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
            client.DownloadFile(webBrowser.Url, sfd.FileName)
        End If

Als je nog iets moet weten, vraag maar raak! ;)
 
Maar natuurlijk :D:

Code:
        Dim client As New System.Net.WebClient
        Dim sfd As New SaveFileDialog
        sfd.Filter = "All Files (*.*)|*.*"
        sfd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        sfd.FileName = "index.html"
        If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
            client.DownloadFile(webBrowser.Url, sfd.FileName)
        End If

Als je nog iets moet weten, vraag maar raak! ;)

Ok, ik wil ook wel weten hoe ik een browser kan printen via een button...
 
Dat weet ik, maar het is nogal moeilijk om zoals bij internet explorer tekst EN icon
in de adresbalk te krijgen. Framework 2.0 ondersteunt dit nu eenmaal niet. Ik zal je
dan enkel maar de code geven hoe het icon te download van de site, je kan er dan
nog mee doen wat je wilt.

Code:
        Dim client As New System.Net.WebClient
        Dim bytes() As Byte = client.DownloadData(WebBrowser.Url.AbsoluteUri & "favicon.ico")
        Dim img As System.Drawing.Image
        My.Computer.FileSystem.WriteAllBytes(Application.StartupPath & "\favicon.ico", bytes, False)
        img = Image.FromFile(Application.StartupPath & "\favicon.ico")
        'Je kan bvb 'img' laten tonen in een panel of  picturebox
 
Dat weet ik, maar het is nogal moeilijk om zoals bij internet explorer tekst EN icon
in de adresbalk te krijgen. Framework 2.0 ondersteunt dit nu eenmaal niet. Ik zal je
dan enkel maar de code geven hoe het icon te download van de site, je kan er dan
nog mee doen wat je wilt.

Code:
        Dim client As New System.Net.WebClient
        Dim bytes() As Byte = client.DownloadData(WebBrowser.Url.AbsoluteUri & "favicon.ico")
        Dim img As System.Drawing.Image
        My.Computer.FileSystem.WriteAllBytes(Application.StartupPath & "\favicon.ico", bytes, False)
        img = Image.FromFile(Application.StartupPath & "\favicon.ico")
        'Je kan bvb 'img' laten tonen in een panel of  picturebox
waar moet ik dat dan plaatsen en wat moet ik veranderen?
 
Laatst bewerkt:
In de ProgressChanged Event van de webbrowser:
Code:
    Private Sub WebBrowser_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser.ProgressChanged
        If Not WebBrowser.IsBusy Then
            Dim bytes() As Byte = client.DownloadData(WebBrowser.Url.AbsoluteUri & "favicon.ico")
            Dim img As System.Drawing.Image
            My.Computer.FileSystem.WriteAllBytes(Application.StartupPath & "\favicon.ico", bytes, False)
            img = Image.FromFile(Application.StartupPath & "\favicon.ico")
            'Je kan bvb 'img' laten tonen in een panel of  picturebox
        End If
    End Sub
 
In de ProgressChanged Event van de webbrowser:
Code:
    Private Sub WebBrowser_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser.ProgressChanged
        If Not WebBrowser.IsBusy Then
            Dim bytes() As Byte = client.DownloadData(WebBrowser.Url.AbsoluteUri & "favicon.ico")
            Dim img As System.Drawing.Image
            My.Computer.FileSystem.WriteAllBytes(Application.StartupPath & "\favicon.ico", bytes, False)
            img = Image.FromFile(Application.StartupPath & "\favicon.ico")
            'Je kan bvb 'img' laten tonen in een panel of  picturebox
        End If
    End Sub
hij zegd dat "client" fout is
 
Sorry, mijn fout ... je moet nog in die subroutine toevoegen:
Code:
Dim client As New System.Net.WebClient
 
wat moet ik veranderen aan de code, omdat ik nergens dat logo zie...

logo???

Wat er eigenlijk moet staan is:
Code:
    Private Sub WebBrowser_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser.ProgressChanged
        If Not WebBrowser.IsBusy Then
            [COLOR="Red"]Dim client As New System.Net.WebClient[/COLOR]
            Dim bytes() As Byte = client.DownloadData(WebBrowser.Url.AbsoluteUri & "favicon.ico")
            Dim img As System.Drawing.Image
            My.Computer.FileSystem.WriteAllBytes(Application.StartupPath & "\favicon.ico", bytes, False)
            img = Image.FromFile(Application.StartupPath & "\favicon.ico")
            'Je kan bvb 'img' laten tonen in een panel of  picturebox
        End If
    End Sub
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan