Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Get scheme, user information, original string and local path associated with Uri using “Uri” class in vb.net - C# .net.

Author: Maliha Atteeq
Download Source Code : 1050_application.zip

In this simple article you will know how we can get scheme, user information, original string and local path associated with Uri using “Uri” class in vb and C #.net.

Uri:

A URI is a compact representation of a resource available to your application on the intranet or Internet. The Uri class defines the properties and methods for handling Uri’s, including parsing, comparing, and combining. The Uri class properties are read-only.

Get the scheme:

In order to get the scheme of the Uri, Uri class provides us a property named as Scheme. This property returns the scheme associated with the specified Uri. The return type of this property is string.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getScheme_Click(object sender, EventArgs e)

        {

            string scheme;

            scheme=obj.Scheme;

            MessageBox.Show("the scheme of the uri is " + scheme);

        }

VB:

Private Sub btn_getScheme_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim scheme As String

    scheme = obj.Scheme

    MessageBox.Show("the scheme of the uri is " & scheme)

End Sub

Get the user information:

In order to get the user information related to the Uri, Uri class provides us a property named as UserInfo. This property returns the user information associated with the specified Uri. The user information includes the user name and password and any other information related to the user. The return type of this property is string. If it returns an empty string, it means that no information related to user is associated with this particular Uri.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getUserInfo_Click(object sender, EventArgs e)

        {

            string info;

            info=obj.UserInfo;

            if (info == string.Empty)

            {

                MessageBox.Show("no user related information found");

            }

            else

            {

                MessageBox.Show("user information related to the uri is " + info);

            }

        }

VB:

Private Sub btn_getUserInfo_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim info As String

    info = obj.UserInfo

    If info = String.Empty Then

        MessageBox.Show("no user related information found")

    Else

        MessageBox.Show("user information related to the uri is " & info)

    End If

End Sub

Get the Local Path:

In order to get the local path of the Uri, Uri class provides us a property named as Local Path. This property returns the local path associated with the specified Uri.  Local path represents the local path of the file. The return type of this property is string.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getLocalPath_Click(object sender, EventArgs e)

        {

            string path;

            path = obj.LocalPath;

            MessageBox.Show("the local path of the uri is " + path);

        }

 

 

VB:

Private Sub btn_getLocalPath_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim path As String

    path = obj.LocalPath

    MessageBox.Show("the local path of the uri is " & path)

End Sub

Get the original string:

In order to get the original string of the Uri, Uri class provides us a property named as originalString. This property returns the original string associated with the specified Uri.  Original string is that string which we pass to the constructor of the Uri object. The return type of this property is string.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getOrgString_Click(object sender, EventArgs e)

        {

            string str;

            str = obj.OriginalString;

            MessageBox.Show("original string passed to constructor is "+str);

        }

VB:

Private Sub btn_getOrgString_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim str As String

    str = obj.OriginalString

    MessageBox.Show("original string passed to constructor is " & str)

End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP APPLICATION";

        }

 

VB:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

   Me.Text = "DEVASP APPLICATION"

End Sub

This simple article tells how we can get scheme, user information, original string and local path associated with Uri using “Uri” class in vb and C #.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to create, start, stop, suspend and resume thread using Thread class in VB.net - C#.net Part1

Disclaimer - Privacy
© 2002-2017 DevASP.net