In this article we show how we can know what kind of address is an address. We will use the URI class, which does not allow URLs to work. The class belongs to the URI name space System.
The URI class has property “Scheme” that indicates the type of URI scheme today. The schemes that detects the URI class are:
* UriSchemeFile: tells us that points the direction in which our class is a file URI.
* UriSchemeFtp: the scheme is FTP (File Transfer Protocol)
* UriSchemeGopher: specifies that we can access through URI using the Gopher protocol.
* UriSchemeHttp: access is a URI using the HTTP protocol.
* UriSchemeHttps: the address is https, http secure.
* UriSchemeMailto: tells us that the address is an e-mail, which can be accessed via SMTP.
* UriSchemeNetPipe: tells us that the identifier URI is NetPipe.
* UriSchemeNetTcp: can access through URI using the protocol NetTCP.
* UriSchemeNews: URI is the address of a newsgroup or News.
* UriSchemeNntp: a newsgroup is accessed via NNTP.
The fields above are just reading.
In the following example, create a constant that contains the address from which we obtain information and identify which type of management is our constant.
In Visual Basic:
Const strURL As String = “http://www.wisecodes.com” Dim strDir As New Uri(strURL) Select Case strDir.Scheme Case Uri.UriSchemeFile 'Code for when the address is a file Case Uri.UriSchemeFtp 'Code for when the address is ftp Case Uri.UriSchemeGopher 'Code for when the address is a file Gopher Case Uri.UriSchemeHttp 'Code for when the address is http Case Uri.UriSchemeHttps 'Code for when the address is https Case Uri.UriSchemeMailto 'Code for when the address is an e-mail Case Uri.UriSchemeNetPipe 'Code for when the address is NetPipe Case Uri.UriSchemeNetTcp 'Code for when the address is NetTcp Case Uri.UriSchemeNews 'Code for when the address is a newsgroup Case Uri.UriSchemeNntp 'Code for when the address is a newsgroup 'accessible via NNTP. End Select
In C Sharp
const string strURL = “http://www.wisecodes.com”
Uri strDir = new Uri (strURL);
switch (strDir.Scheme)
{
case Uri.SchemeFile:
//Code for when the address is a file
case Uri.UriSchemeFtp:
//Code for when the address is ftp
case Uri.UriSchemeGopher:
//Code for when the address is a file Gopher
case Uri.UriSchemeHttp:
//Code for when the address is http
case Uri.UriSchemeHttps:
//Code for when the address is https
case Uri.UriSchemeMailto:
//Code for when the address is an e-mail
case Uri.UriSchemeNetPipe:
//Code for when the address is NetPipe
case Uri.UriSchemeNetTcp:
//Code for when the address is NetTcp
case Uri.UriSchemeNews:
//Code for when the address is a newsgroup
caseUri.UriSchemeNntp:
//Code for when the address is a newsgroup
//accessible via NNTP.
}
Link: Via Microsoft
Happy Programming!!


