How to

create path from strings parts

Published: 25. October 2011 | Updated: 25. November 2011
License: Microsoft Public License (MS-PL)
Categories: File system
Tags: C# File System Text
Was this snippet helpful for you? YESYES / NONO

Snippet shows how to create file or directory path from parts

Import namespace

using System.IO;

Code

string mainDirectory = @"C:\Folder";
string directory = "Subdir";
string filename = "test.txt";
            
string path = Path.Combine(mainDirectory, directory, filename);

Console.WriteLine(path);
Console Output:
C:\Folder\Subdir\test.txt
Send us feedback about this snippet »



Related Snippets: