Comment joindre deux chemins de fichier en C#?Comment joindre deux chemins en C#?
79
A
Répondre
129
Vous devez utiliser Path.Combine() comme dans l'exemple ci-dessous:
string basePath = @"c:\temp";
string filePath = "test.txt";
string combinedPath = Path.Combine(basePath, filePath);
// produces c:\temp\test.txt
+12
Cela vaut la peine de noter que si "filePath" contient un chemin absolu, Path.Combine renvoie uniquement " chemin du fichier". 'chaîne basePath = @" c: \ temp \ "; string filePath = @ "c: \ dev \ test.txt";/* pour une raison quelconque */ chaîne combinée = Path.Combine (basePath, filePath); ' produit @" c: \ dev \ test.txt " –
26
System.IO.Path.Combine() est ce que vous avez besoin.
Path.Combine(path1, path2);
que voulez-vous dire par joindre deux chemin? Chemin du fichier en deux parties ou deux fichiers différents? Si le chemin du fichier est en deux parties, utilisez System.IO.Path.Combine (path1, path2). plus d'informations ici [http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx] – TheVillageIdiot