Login(Email) Password Forgot Password Account Settings
Home ASP.net System Info C# Books Java Script Visual C++(MFC) C/C++ Win API Java Contact Us
Path class ChangeExtension Method (Visual Studio 2008 C#)
Returns a copy of the string with a modified extension. If you don’t specify an extension, the current extension is remove(How to change the extension of a file in C#.net visual studio 2008)
Syntax:
public static string ChangeExtension(
    string path,
    string extension
)
Example:
using System;
using System.IO;

public class CPath{

    public static void Main() {     
        string file1 = @"C:\mydir\myfile.com.extension";
        string file2 = @"C:\mydir\";
        string result;

        result = Path.ChangeExtension(file1, ".old");
    
           // result will conatin  'C:\mydir\myfile.com.old'
        result = Path.ChangeExtension(file1, "");
        
  
        // result will conatin   'C:\mydir\myfile.com.'
//If you don’t specify an extension, the current extension is remove
        result = Path.ChangeExtension(file2, ".old");
                
      // result will contain 'C:\mydir\.old'
 
   }
}