copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
'Beispiel: VB .Net - Quelltext einer Werbseite downloaden - 3
'
Option Explicit On
Option Strict On

Imports System.Net

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button1.Click
        Dim url As Uri = New Uri("http://www.visual-basic5.de/vbclassic/dotnet/countdown.htm")
        Dim Result As String = Me.GetSouceCodeFromeWebsite(url)
        If Result IsNot String.Empty Then
            Me.RichTextBox1.Text = Result
        Else
            MessageBox.Show("Quelltext konnte nicht aus:" & System.Environment.NewLine & _
                url.ToString() & System.Environment.NewLine & _
                " extrahiert werden.", "Info")
        End If
    End Sub

    Private Function GetSouceCodeFromeWebsite(ByVal url As Uri) As String
        Try
            Dim Source As String = String.Empty
            Using wc As New WebClient
                Source = wc.DownloadString(url)
            End Using
            Return Source
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString(), "Info")
        End Try
        Return String.Empty
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        Me.CenterToScreen()
    End Sub

End Class
Sourcecode Visual Basic