How do I join two paths in C#?

前端 未结 2 844
感情败类
感情败类 2020-12-04 17:04

How do I join two file paths in C#?

相关标签:
2条回答
  • 2020-12-04 17:39

    System.IO.Path.Combine() is what you need.

    Path.Combine(path1, path2);
    
    0 讨论(0)
  • 2020-12-04 18:02

    You have to use Path.Combine() as in the example below:

    string basePath = @"c:\temp";
    string filePath = "test.txt";
    string combinedPath = Path.Combine(basePath, filePath); 
    // produces c:\temp\test.txt
    
    0 讨论(0)
提交回复
热议问题