Program that uses Path methods [C#]

Posted by senthil | 7:40:00 PM | , | 0 comments »

Path handles file path processing.Its a major thing the Path type in the System.IO namespace. Its very critical when using directly with paths.

Examples

If you need to extract filename path in your program. You can access it by adding "using System.IO" at the top of your class.

Console


using System;
using System.IO;

class Program
{
    static void Main()
    {
 string path = "C:\\stagelist.txt";

 string extension = Path.GetExtension(path);
 string filename = Path.GetFileName(path);
 string filenameNoExtension = Path.GetFileNameWithoutExtension(path);
 string root = Path.GetPathRoot(path);

 Console.WriteLine("{0}\n{1}\n{2}\n{3}",
     extension,
     filename,
     filenameNoExtension,
     root);
    }
}
Output

.txt
stagelist.txt
stagelist
C:\

0 comments

Related Posts Plugin for WordPress, Blogger...