URI Manipulation with .Net's URI Class

Discussion in 'Visual Basic [VB]' started by pradeep, Mar 27, 2007.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Uniform Resource Identifiers (URIs) may represent Web requests, FTP requests, files, news, and e-mail. Whenever you need to work with URIs and determine a particular portion of a given URI, you can utilize the System.URI class available in Visual Studio .NET. This class allows you to represent and easily manipulate a given URI.

    To create an example, add a ListBox control to your form and call it ListBox1. Then, add the code in Snippet A.

    Snippet A

    Code:
    Private Sub GetURIInfo()
          Dim strURI As New Uri("http://www.go4expert.com/showthread.php?p=10432")
          With ListBox1.Items
              .Clear()
              .Add("Scheme: " & strURI.Scheme)
              .Add("Host: " & strURI.Host)
              .Add("Path: " & strURI.AbsolutePath)
              .Add("Query: " & strURI.Query)
              .Add("Type: " & strURI.HostNameType.ToString())
              .Add("Port: " & strURI.Port)
          End With
      End Sub
    In the code, we initially define a strURI variable and set its value to a link from the Go4Expert forums. Then, we add the following properties of the URI object strURI to the ListBox1 control: Scheme, Host, Path, Query, Type, Port. The ListBox1 control simply displays the selected properties of the strURI object.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice