1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

URI Manipulation with .Net's URI Class

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

  1. pradeep

    pradeep Team Leader

    Apr 4, 2005
    Likes Received:
    Trophy Points:
    Kolkata, India
    Home Page:
    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

    Private Sub GetURIInfo()
          Dim strURI As New Uri("http://www.go4expert.com/showthread.php?p=10432")
          With ListBox1.Items
              .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