Monday 30 July 2012

.Net Tips, C# Tips : Create a well formed URI using UriBuilder class with C# Examples and VB.Net Examples

You can use System.UriBuilder class to build a new well-formed URI.
You can also say create a well-formed URL.
You need to set some property of UriBuilder object's , like Scheme , Port , Host , Path etc....
You can get generated URI using AbsoluteUri Method.
This is very useful article for .Net Beginners.

Here is example for this.
In this example we construct one URI using UriBuilder Class.

C# Examples :
    // Generate a new URI.
    UriBuilder objUri = new UriBuilder();
    objUri.Scheme = "http";
    objUri.Port = 80;
    objUri.Host = "www.microsoft.com";
    objUri.Path = "en-us/default.aspx";

    Response.Write("<b>Genereted URI:</b> " + objUri.Uri.AbsoluteUri);

VB.net Examples :
        ' Generate a new URI.
        Dim objUri As New UriBuilder()
        objUri.Scheme = "http"
        objUri.Port = 80
        objUri.Host = "www.microsoft.com"
        objUri.Path = "en-us/default.aspx"

        Response.Write("<b>Genereted URI:</b> " + objUri.Uri.AbsoluteUri)

Output :


This type of C# Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



No comments:

Post a Comment