تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] مشكلة في كود Dim website As String
#1
سلام  عليكم 

عندي مشكلة  من  هي كود  

كود :
    Dim website As String = TextBox1.Text
           Dim html As String = New Net.WebClient() With {.Encoding = System.Text.Encoding.UTF8}.DownloadString(website)

اذا  موقع  لا يشتغل  يعطيني  خطاء  في 
كود :
    Dim html As String = New Net.WebClient() With {.Encoding = System.Text.Encoding.UTF8}.DownloadString(website)

اريد  كود if  اذا موقع  يشتغل  يعطيني  string  اذا لايشتغل  يروح الي موقع  ثاني 

شكرا   Heart Heart
الرد }}}
تم الشكر بواسطة:
#2
كود :
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim FirstUrl As New System.Uri("http://www.yourURLhere.com/")
        Dim OtherURl As New System.Uri("http://www.dreamincode.net/forums/topic/137663-check-if-url-exists/")

        If isServerAccessible(FirstUrl) = True Then
            MessageBox.Show("Work")
        Else
            MessageBox.Show("Not Work")
        End If

        If isServerAccessible(OtherURl) = True Then
            MessageBox.Show("Work")
        Else
            MessageBox.Show("Not Work")
        End If
    End Sub

    Private Function isServerAccessible(ByVal HostAddress As Uri) As Boolean
        Try
            'First check if the computer has net access at all. 
            'Second check if the host is reachable and how good the speed of respond is. 
            'The host address can be a computer name, IP-address or you can create URL form Uri class.
            If My.Computer.Network.IsAvailable AndAlso My.Computer.Network.Ping(HostAddress, 1000) Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
    End Function



استخدمه بالطريقة التي تناسبك  ،  بالاضافة يجب عليك التحقق هل يوجد بالاساس مشكله بالاتصال بالسيرفر ام لا يوجد انترنت بجهازك و هذه الطريقة تعمل على ذلك ، تتحقق هل انت متصل بالانترنت بالاساس ام لا  ثم تفحص وجود  URL   على الويب .

بالتوفيق
اسم معرفي : محمد يحيى
الرد }}}
تم الشكر بواسطة: ممدوح , ممدوح



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم