This can be accomplished in many ways.
Maybe what you're lacking is knowledge of the System.IO.Path
class (MSDN article here).
For instance changing the extension could be accomplished like so:
string originalFilePath = @"D:\Project\File\xxx.csv";
string newFilePath = Path.ChangeExtension(originalFilePath, ".txt");
Note: You need to explicitate the leading dot (".") for the extension.
Here's some "Path algebra" fun you could combine to create your desired effects:
string originalFilePath = @"D:\Project\File\xxx.csv";
string thePath = Path.GetDirectoryName(originalFilePath);
// will be @"D:\Project\File"
string filename = Path.GetFileName(originalFilePath);
// will be "xxx.csv"
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(originalFilePath);
// will be "xxx"
string recombinedFilePath = Path.Combine( @"D:\OtherFolder", "somethingElse.txt" );
// will be @"D:\OtherFolder\somethingElse.txt"
Note: Path.Combine
knows how to handle extra/missing leading/trailing backslashes.
For example:
Path.Combine(@"D:\MyFolder1", @"MyFolder2\MyFile.txt")
Path.Combine(@"D:\MyFolder1\", @"MyFolder2\MyFile.txt")
Path.Combine(@"D:\MyFolder1", @"\MyFolder2\MyFile.txt")
Path.Combine(@"D:\MyFolder1\", @"\MyFolder2\MyFile.txt")
will all yield the same result: @"D:\MyFolder1\MyFolder2\MyFile.txt"