WebBrowserUriTypeConverter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / WebBrowserUriTypeConverter.cs / 1 / WebBrowserUriTypeConverter.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 
using System;
using System.ComponentModel; 
 
namespace System.Windows.Forms
{ 
    class WebBrowserUriTypeConverter : UriTypeConverter
    {
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        { 
            //The UriTypeConverter gives back a relative Uri for things like "www.microsoft.com".  If
            //the Uri is relative, we'll try sticking "http://" on the front to see whether that fixes it up. 
            Uri uri = base.ConvertFrom(context, culture, value) as Uri; 
            if (uri != null && !string.IsNullOrEmpty(uri.OriginalString) && !uri.IsAbsoluteUri)
            { 
                try
                {
                    uri = new Uri("http://" + uri.OriginalString.Trim());
                } 
                catch (UriFormatException)
                { 
                    //We can't throw "http://" on the front: just return the original (relative) Uri, 
                    //which will throw an exception with reasonable text later.
                } 
            }
            return uri;
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 
using System;
using System.ComponentModel; 
 
namespace System.Windows.Forms
{ 
    class WebBrowserUriTypeConverter : UriTypeConverter
    {
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        { 
            //The UriTypeConverter gives back a relative Uri for things like "www.microsoft.com".  If
            //the Uri is relative, we'll try sticking "http://" on the front to see whether that fixes it up. 
            Uri uri = base.ConvertFrom(context, culture, value) as Uri; 
            if (uri != null && !string.IsNullOrEmpty(uri.OriginalString) && !uri.IsAbsoluteUri)
            { 
                try
                {
                    uri = new Uri("http://" + uri.OriginalString.Trim());
                } 
                catch (UriFormatException)
                { 
                    //We can't throw "http://" on the front: just return the original (relative) Uri, 
                    //which will throw an exception with reasonable text later.
                } 
            }
            return uri;
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK