NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

File.ChangeExtension

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;

Parameters

path
The path of the file.
extension
The new file extension (with a leading period), or null to remove the extension.

Return Value

Path with the new file extension.

Exceptions

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.

Remarks

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.

Requirements

NGWS Runtime Security:

FileIOPermissionAccess Write permission to the file.

See Also

File Class | File Members | System.IO Namespace