Changes a file extension.
[Visual Basic] Public Shared Function ChangeExtension( _ ByVal path As String, _ ByVal extension As String _ ) As String [C#] public static string ChangeExtension( string path, string extension ); [C++] public: static String* ChangeExtension( String* path, String* extension ); [JScript] public static function ChangeExtension( path : String, extension : String ) : String;
Path with the new file extension.
Exception Type | Condition |
---|---|
IOException | An I/O error occurs. |
SecurityException | The caller does not have the required permission. |
ArgumentException | The file name is empty or contains only whitespaces. |
The path parameter specifies a file path, and the extension parameter specifies a file extension (with a leading period, such as ".exe" or ".cs").
The function returns a file path with the same root, directory, and base name parts as path, but with the file extension changed to the specified extension. If path is null, the function returns null. If path does not contain a file extension, the new file extension is appended to the path. If extension is null, any existing extension is removed from path.
NGWS Runtime Security:
FileIOPermissionAccess | Write permission to the file. |