Get full path without filename in C#
To get full path without filename in C#, we callPath.GetDirectoryName()
method and then call Path.GetFullPath()
using result.Remember to include namespace:
using System.IO;
Example
using System;
using System.IO;
public class Example
{
public static void Main()
{
string fileAndPath = @"c:\test\demo.xml";
string currentDirectory = Path.GetDirectoryName(fileAndPath);
string fullPathOnly = Path.GetFullPath(currentDirectory);
Console.WriteLine(fullPathOnly);
}
}