Open Site from Windows application


This code snippet is related to open site/URL from the windows application.

In some cases, we need to open the website from the windows application. In that case, we need to check the URI.

URI can contain spaces as well as some special characters. SO that we need to convert that characters in such way we can able to open the site.

Like if there is a space in the URI, it will be converted by %20.

If you want to open site from your windows application, you can use following code.

First of all, It will check the URI.

Secondly,It will convert the spaces and special characters in appropriate form so that we can open the website.

Then, Open the URI, if it is well formed string.

// Create new URI object by passing the uri string
Uri uriString = new Uri("");
// Sometimes there are spaces and special characters in the URI.
// Following code replace the spaces as per the Http rules
string absUriString = uriString.AbsoluteUri.ToString();
// Check the URI is wellformed string or not if(Uri.IsWellFormedUriString(uriString.AbsoluteUri.ToString(),UriKind.Absolute))
//Start the process if URI is correct. It will open the site in default
// browser


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: