Class FilePathHelper
- Namespace
- Dynamicweb.Core.Helpers
- Assembly
- Dynamicweb.Core.dll
public static class FilePathHelper
- Inheritance
-
FilePathHelper
- Inherited Members
Methods
ContainsPathTraversal(string?)
Determines whether a folder contains a directory-traversal (..) segment. Splits on both separators so mixed forms are caught.
public static bool ContainsPathTraversal(string? folder)
Parameters
folderstringThe folder to check.
Returns
- bool
trueif a segment is..; otherwisefalse.
GetAbsolutePath(string)
Gets absolute path
public static string GetAbsolutePath(string path)
Parameters
pathstringThe path value. Could be relative or filename
Returns
GetAbsolutePath(string, string?)
Gets absolute path
public static string GetAbsolutePath(string path, string? defaultFolder)
Parameters
pathstringThe path value. Could be relative or filename
defaultFolderstringThe folder path added to relative path in case the value is need to be corrected.
Returns
GetRelativePath(string)
Gets correct relative path
public static string GetRelativePath(string path)
Parameters
pathstringThe path value. Could be relative or absolute or filename
Returns
GetRelativePath(string, string?)
Gets correct relative path
public static string GetRelativePath(string path, string? defaultFolder)
Parameters
pathstringThe path value. Could be relative or absolute or filename
defaultFolderstringThe folder path added to relative path in case the value is need to be corrected.
Returns
GetValidFileOrFolderName(string)
Sanitizes the given file or folder name, and replaces all illegal characters with '_'
public static string? GetValidFileOrFolderName(string name)
Parameters
namestringThe file or folder name which should be sanitized.
Returns
- string
The sanitized file or folder name which only contains legal characters
IsUrl(string)
public static bool IsUrl(string path)
Parameters
pathstring
Returns
IsWithinRoot(string, string, out string)
Determines whether path resolves inside root, resolving a relative
path against root rather than the process working directory.
public static bool IsWithinRoot(string root, string path, out string resolvedPath)
Parameters
rootstringThe absolute root folder.
pathstringThe absolute or root-relative path to check.
resolvedPathstringThe fully resolved
path.
Returns
- bool
trueif the resolved path is the root or inside it; otherwisefalse.
ValidateFilename(string)
Validates the given filename with path.
public static bool ValidateFilename(string fileNameWithPath)
Parameters
fileNameWithPathstringThe filename with path to validate
Returns
- bool
trueif filename and path is valid;falseotherwise.