How to replace a File extension in C# ?

Published on November 13, 2014 by abundantcode

Filed under C#

Last modified November 13, 2014

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3559 times

If you want to replace a file extension in C# , you can use the ChangeExtension method defined in the System.IO.Path class.

Below is a sample code snippet demonstrating how to do it.

How to replace a File extension in C# ?

string fileName = @"C:\test.new";
var result;
result = Path.ChangeExtension(fileName, ".old");
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to read file contents from command line in Windows 10 ?

You can use the command "type" in the command line to read the contents of the text file i...

How to Copy the entire contents of a directory in C# ?

Below is a sample code snippets that demonstrates how to copy the entire contents of a directory to ...

How to Delete a File in C# ?

Below is a sample code snippet that demonstrates how to delete a file in C# . How to Delete a File ...