Jak połączyć dwie ścieżki plików w C #?
Jak połączyć dwie ścieżki plików w C #?
Odpowiedzi:
Musisz użyć Path.Combine () jak w poniższym przykładzie:
string basePath = @"c:\temp";
string filePath = "test.txt";
string combinedPath = Path.Combine(basePath, filePath);
// produces c:\temp\test.txt
string basePath = @"c:\temp\"; string filePath = @"c:\dev\test.txt"; /* for whatever reason */ string combined = Path.Combine(basePath, filePath);
produkuje @ "c: \ dev \ test.txt"
System.IO.Path.Combine () jest tym, czego potrzebujesz.
Path.Combine(path1, path2);