Combine two strings into a path in CSharp

Description

The following code shows how to combine two strings into a path.

Example


  /*from  w w  w. j a v  a  2s. c  om*/
  
  
     

using System;
using System.IO;

public class MainClass {

    public static void Main() {

        string path1 = "c:\\temp";
        string path2 = "subdir\\file.txt";

        string combination = Path.Combine(path1, path2);
        Console.WriteLine(combination);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip