Answers for "how to find extension of file in c#"

C#
5

c# get file extension

string myFilePath = @"C:\MyFile.txt";
string ext = Path.GetExtension(myFilePath);
// ext would be ".txt"
Posted by: Guest on August-11-2020
1

how to change the extension of a file C#

//There is: Path.ChangeExtension method. E.g.:
var result = Path.ChangeExtension(myffile, ".jpg");

//In the case if you also want to physically change the extension, you could use File.Move method:
File.Move(myffile, Path.ChangeExtension(myffile, ".jpg"));
Posted by: Guest on September-21-2021

Code answers related to "how to find extension of file in c#"

C# Answers by Framework

Browse Popular Code Answers by Language