How to Combine a Filename with a Directory in C# ?

If you need to combine the filename with a directory name in C# , use the built in Path class to do it instead of doing it manually.

How to Combine a Filename with a Directory in C# ?

Below is a sample code snippet demonstrating how to use Path.Combine method in C#.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.IO;
namespace AbundantcodeConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
           string path = Path.Combine(@"C:\Abundantcode\","Program.exe");
           Console.WriteLine(path);
           Console.ReadLine();
        }     
    }
    
}

Leave Your Comment

Liked this content?. Please spread the word :)