C# Program to Demonstrate the Operations of C# Path Class

This is a C# Program to demonstrate the operations of C# path class.

Problem Description

This C# Program Demonstrates the Operations of C# Path Class.

Problem Solution

Here a path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk.

Program/Source Code

Here is source code of the C# Program to Demonstrate the Operations of C# Path Class. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Demonstrate the Operations of C# Path Class
 */
using System;
using System.IO;
class Test
{
    public static void Main()
    {
        string p = @"c:\srip\sri.txt";
        string p2 = @"c:\srip\sri";
        string p3 = @"srip";
        if (Path.HasExtension(p))
        {
            Console.WriteLine("{0} has an extension.", p);
        }
        if (!Path.HasExtension(p2))
        {
            Console.WriteLine("{0} has no extension.", p2);
        }
        if (!Path.IsPathRooted(p3))
        {
            Console.WriteLine("The string {0} contains no root information.", p3);
        }
        Console.WriteLine("Location for Temporary Files : {0}", Path.GetTempPath());
        Console.WriteLine("Full path of {0} is {1}.", p3, Path.GetFullPath(p3));
        Console.WriteLine("File available for Use : {0} ", Path.GetTempFileName());
        Console.Read();
 
    }
}
Program Explanation

This C# program is used to demonstrate the operations of c# path class. If condition statement is used to check the value in IsPathRooted() function is not equal to the argument value. The IsPathRooted() function is used to get a value indicating whether the specified path string contains a root.

advertisement
advertisement

If the condition is true then execute the iteration of the statement. The path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk.

Runtime Test Cases
 
c:\srip\sri.txt has an extension.
c:\srip\sri has no extension.
The string srip contains no root information.
Location For Temporary Files : C:\Users\Win7\appdata\local\temp\
Full Path of Temp : D:\sri\ConsoleApplication22\ConsoleApplication22\bin\Debug\srip.
File Available for Use : C:\Users\Win7\appdata\local\temp\trmpEB1B.tmp

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.