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


This content was proof-read by Grammarly. You can Try Grammary for FREE

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#.


Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book BUY & DOWNLOAD GRAPHQL.NET COOKBOOK
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();
        }     
    }
    
}
%d bloggers like this: