Class FilenameHelper
- Namespace
- VisioForge.Core.Helpers
- Assembly
- VisioForge.Core.dll
Provides utility methods for working with file names, extensions, and paths.
public static class FilenameHelperInheritance
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
filenamestring-
The original file name whose extension will be changed.
extstring-
The new extension to apply (should include the period, e.g., ".txt").
contextBaseContext?-
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.
FileUriToLocalPath(string)
Returns the local path of a file: URI string, or the original string when it is not one.
public static string FileUriToLocalPath(string value)Parameters
valuestring-
A
file:URI, a local path or a URL.
Returns
- string
-
The local path, or
value.
Remarks
Accepts file:///, file://localhost/, and file:/ URI forms and decodes escaped path characters.
On macOS, Linux, Android and iOS a drive-shaped path is a path: file:///C:/x.mp4 gives /C:/x.mp4.
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
fileNamestring-
The file name from which to extract the extension. Cannot be
null. contextBaseContext?-
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
fileNameisnull.
IsAudioFile(string)
Determines whether the specified file name represents an audio file based on its extension.
public static bool IsAudioFile(string filename)Parameters
filenamestring-
The file name to check.
Returns
- bool
-
trueif 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
filenamestring-
The file name to check.
Returns
- bool
-
trueif 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
pathstring-
The path to check.
Returns
- bool
-
trueif 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
uriUri-
The URI to check.
Returns
- bool
-
trueif the URI represents a UNC path; otherwise,false.
IsUrl(string)
Determines whether the specified string is a non-file URI: a "scheme://" URI or a data: URI.
A local path, a file: URI and a name that merely contains a colon are not URLs.
public static bool IsUrl(string path)Parameters
pathstring-
The string to check.
Returns
- bool
-
trueif the string is a non-file URI; otherwise,false.
SafeCreateFileUri(string)
Creates a Uri object from the specified file name, safely handling both absolute and relative paths.
A file: URI string (file:///C:/video.mp4, file://localhost/tmp/video.mp4) is accepted as well
and returned as a URI.
public static Uri SafeCreateFileUri(string fileName)Parameters
fileNamestring-
The file name or path to convert to a URI. Can be either an absolute or relative path, or a
file:URI.