string filePath = "C:\\Documents\\example.txt"; string newFilePath = Path.ChangeExtension(filePath, ".doc"); Console.WriteLine(newFilePath); // Output: C:\Documents\example.doc
string filePath = "C:\\Documents\\example.txt"; string newFilePath = Path.ChangeExtension(filePath, null); Console.WriteLine(newFilePath); // Output: C:\Documents\exampleThis example demonstrates how to use the ChangeExtension method to remove the file extension from a given file path altogether. To do this, we simply pass a null value as the second argument. The method returns a string which is the updated file path without any extension. In this case, the output will be "C:\Documents\example". Package Library: System.IO