Table of Contents

Class FilenameHelper

Namespace
VisioForge.Core.Helpers
Assembly
VisioForge.Core.dll

Provides utility methods for working with file names, extensions, and paths.

public static class FilenameHelper

Inheritance

Inherited Members

Methods

ChangeFileExt(string, string, BaseContext?)

Changes the file extension of the specified file name to a new extension.

public static string ChangeFileExt(string filename, string ext, BaseContext? context = null)

Parameters

filename string

The original file name whose extension will be changed.

ext string

The new extension to apply (should include the period, e.g., ".txt").

context BaseContext?

Optional logging context. Reserved for future error reporting; signature kept consistent with VisioForge.Core.Helpers.FilenameHelper.GetFileExt(System.String,VisioForge.Core.BaseContext).

Returns

string

The file name with the new extension, or the original file name if no extension was found.

Remarks

Delegates to ChangeExtension(String, String) which only modifies the trailing extension. The previous string-Replace implementation corrupted paths where the extension substring also appeared in a parent directory name — e.g. "C:\.mp4 backups\video.mp4" with old=".mp4", new=".avi" became "C:\.avi backups\video.avi", breaking the directory portion of the path.

GetFileExt(string, BaseContext?)

Gets the file extension from the specified file name, including the period.

public static string GetFileExt(string fileName, BaseContext? context = null)

Parameters

fileName string

The file name from which to extract the extension. Cannot be null.

context BaseContext?

Optional context for error logging and diagnostics.

Returns

string

The file extension including the period (e.g., ".txt"), or an empty string if no extension is found.

Exceptions

ArgumentNullException

Thrown when fileName is null.

IsAudioFile(string)

Determines whether the specified file name represents an audio file based on its extension.

public static bool IsAudioFile(string filename)

Parameters

filename string

The file name to check.

Returns

bool

true if the file extension matches common audio formats (WAV, MP3, OGG, M4A, FLAC, OPUS, SPEEX, WMA); otherwise, false.

IsImageFile(string)

Determines whether the specified file name represents an image file based on its extension.

public static bool IsImageFile(string filename)

Parameters

filename string

The file name to check.

Returns

bool

true if the file extension matches common image formats (BMP, JPG, JPEG, GIF, PNG, TIF, TIFF); otherwise, false.

IsUNCPath(string)

Determines whether the specified path is a UNC (Universal Naming Convention) path. Extended-length paths (\?</code>) and device paths (\.</code>) are excluded unless they use the UNC form (\?\UNC</code>).

public static bool IsUNCPath(string path)

Parameters

path string

The path to check.

Returns

bool

true if the path is a UNC path; otherwise, false.

IsUNCPath(Uri)

Determines whether the specified URI represents a UNC (Universal Naming Convention) path.

public static bool IsUNCPath(Uri uri)

Parameters

uri Uri

The URI to check.

Returns

bool

true if the URI represents a UNC path; otherwise, false.

IsUrl(string)

Determines whether the specified string is a network URL (http, https, rtsp, rtmp, rtsps, rtmps, mms, ftp, udp, tcp, srt).

public static bool IsUrl(string path)

Parameters

path string

The string to check.

Returns

bool

true if the string is a network URL; otherwise, false.

SafeCreateFileUri(string)

Creates a Uri object from the specified file name, safely handling both absolute and relative paths.

public static Uri SafeCreateFileUri(string fileName)

Parameters

fileName string

The file name or path to convert to a URI. Can be either an absolute or relative path.

Returns

Uri

A Uri object representing the file. Relative paths are converted to absolute paths before creating the URI.