ChangeExtension Method
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Changes the extension of a path string.
Namespace: System.IO
Assembly: System.IO (in System.IO.dll)
Syntax
'Declaration
Public Shared Function ChangeExtension ( _
path As String, _
extension As String _
) As String
public static string ChangeExtension(
string path,
string extension
)
public:
static String^ ChangeExtension(
String^ path,
String^ extension
)
static member ChangeExtension :
path:string *
extension:string -> string
public static function ChangeExtension(
path : String,
extension : String
) : String
Parameters
- path
Type: System. . :: . .String
The path information to modify. The path cannot contain any of the characters defined in GetInvalidPathChars.
- extension
Type: System. . :: . .String
The new extension (with or without a leading period). Specify nullNothingnullptrunita null reference (Nothing in Visual Basic) to remove an existing extension from path.
Return Value
Type: System. . :: . .String
The modified path information.
Remarks
If neither path nor extension contains a period (.), ChangeExtension adds the period.
The extension parameter can contain multiple periods and any valid path characters, and can be any length. If extension is null Nothing nullptr unit a null reference (Nothing in Visual Basic) , the returned string contains the contents of path with the last period and all characters following it removed.
If extension is an empty string, the returned path string contains the contents of path with any characters following the last period removed.
If path does not have an extension and extension is not null Nothing nullptr unit a null reference (Nothing in Visual Basic) , the returned string contains path followed by extension.
If extension is not null Nothing nullptr unit a null reference (Nothing in Visual Basic) and does not contain a leading period, the period is added.
If path contains a multiple extension separated by multiple periods, the returned string contains the contents of path with the last period and all characters following it replaced by extension. For example, if path is "\Dir1\examples\pathtests.csx.txt" and extension is "cs", the modified path is "\Dir1\examples\pathtests.csx.cs".
It is not possible to verify that the returned results are valid in all scenarios. For example, if path is empty, extension is appended.
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.