C# windows application

csharp , windows application , connection Shah Alam, Malaysia
  • 12 years ago
    Hello, Please i am trying to develop a program that will connect to the internet using C# windows application, however do i need to set up a localhost to connect to internet.
  • 11 years ago

    Hi, you do not need to setup localhost for C# windows application that will connect to the internet. However, if you want to test the application in offline environment, eg. without internet connection, you may want to setup the localhost. And your application can connect to localhost for the testing. Hope this information is helpful.

  • 11 years ago

    its quite easy to connect to the internet and fetch pages you can use that code below

    Imports System.Net
    Imports System.IO
    
    Public Class AWebFetcher
        Private _nodename As String
    
    
        Public Event DataReceived(ByVal node As String, ByVal _data As String)
        Public Event ErrorReceived(ByVal node As String, ByVal _errmsg As String)
    
        Public Sub New(ByVal node As String)
            _nodename = node
        End Sub
    
        Public Sub Fetch(ByVal _url As String)
            'First, you need to convert URL of the webpage from text format, to "System.Uri".
            Dim requestUri As New Uri(_url)
    
            'Then, we will create the "WebClient".
            Dim wc As New WebClient
    
    
            'Followed by adding the "link" to the "I_Receive_Data" Event Handler (when download finishes, it gets the webpage source)
            AddHandler wc.DownloadStringCompleted, AddressOf I_Receive_Data
    
            'Trap for possible network errors
            Try
                wc.DownloadStringAsync(requestUri)
            Catch ex As WebException
                RaiseEvent ErrorReceived(_nodename, ex.Message)
            End Try
        End Sub
    
        Private Sub I_Receive_Data(ByVal sender As Object, ByVal e As System.Net.DownloadStringCompletedEventArgs)
            'Remember, the "DownloadStringCompleted" event fires even if error happened in download process
            If Not e.Error Is Nothing Then Exit Sub
            'We checked it by the e.Error argument
            'e.Result contains requested webpage as a string
            RaiseEvent DataReceived(_nodename, e.Result)
        End Sub
    End Class
    

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debuggers don't remove bugs. They only show them in slow motion.”