Home » C#

C# | Uri.IsFile Property with Example

Uri.IsFile Property: Here, we are going to learn about the IsFile Property of Uri class with example in C#.
Submitted by Nidhi, on March 28, 2020

Uri.IsFile Property

Uri.IsFile Property is instance property of Uri class which used to check that specified Uri is a file Uri or not. This property returns a boolean value. If specified Uri is a file Uri then it returns true otherwise it returns false. This property may generate System.InvalidOperationException exception.

Syntax:

    public bool IsFile { get; }

Return value:

The return type of this property is Boolean, it returns a Boolean value that is true if the Uri is a file URI; otherwise, false.

Example to demonstrate example of Uri.IsFile Property

using System;

class UriExample
{
    //Entry point of Program
    static public void Main()
    {
        Uri domainUri;
        Uri domainUri1;

        domainUri = new Uri("https://www.includehelp.com:8082");
        domainUri1 = new Uri("file://myServer/article.text");

        if (domainUri.IsFile)
            Console.WriteLine("Given Uri is a file Uri");
        else
            Console.WriteLine("Given Uri is not a file Uri");


        if (domainUri1.IsFile)
            Console.WriteLine("Given Uri is a file Uri");
        else
            Console.WriteLine("Given Uri is not a file Uri");
    }
}

Output

Given Uri is not a file Uri
Given Uri is a file Uri

In the above program, we created an object of Uri class initialized with website name with port number and here we checked given Uri is a file Uri or not using IsFile property of Uri class.

Reference: Uri.IsFile Property



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.