How to

change file extension

Published: 25. October 2011 | Updated: 25. October 2011
License: Microsoft Public License (MS-PL)
Categories: File system » Files
Tags: C# File System Text
Was this snippet helpful for you? YESYES / NONO

Snippet code shows how to change file extension.

Import namespace

using System.IO;

Code

string path = @"C:\Test\file.txt";
string newExtension = "jpg";

string changed = Path.ChangeExtension(path, newExtension);

// renames file
File.Move(path, changed);

Console.WriteLine(changed);
Console Output:
C:\Test\file.jpg
Send us feedback about this snippet »



Related Snippets: