Table of Contents

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

folder string

The folder to check.

Returns

bool

true if a segment is ..; otherwise false.

GetAbsolutePath(string)

Gets absolute path

public static string GetAbsolutePath(string path)

Parameters

path string

The path value. Could be relative or filename

Returns

string

GetAbsolutePath(string, string?)

Gets absolute path

public static string GetAbsolutePath(string path, string? defaultFolder)

Parameters

path string

The path value. Could be relative or filename

defaultFolder string

The folder path added to relative path in case the value is need to be corrected.

Returns

string

GetRelativePath(string)

Gets correct relative path

public static string GetRelativePath(string path)

Parameters

path string

The path value. Could be relative or absolute or filename

Returns

string

GetRelativePath(string, string?)

Gets correct relative path

public static string GetRelativePath(string path, string? defaultFolder)

Parameters

path string

The path value. Could be relative or absolute or filename

defaultFolder string

The folder path added to relative path in case the value is need to be corrected.

Returns

string

GetValidFileOrFolderName(string)

Sanitizes the given file or folder name, and replaces all illegal characters with '_'

public static string? GetValidFileOrFolderName(string name)

Parameters

name string

The 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

path string

Returns

bool

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

root string

The absolute root folder.

path string

The absolute or root-relative path to check.

resolvedPath string

The fully resolved path.

Returns

bool

true if the resolved path is the root or inside it; otherwise false.

ValidateFilename(string)

Validates the given filename with path.

public static bool ValidateFilename(string fileNameWithPath)

Parameters

fileNameWithPath string

The filename with path to validate

Returns

bool

true if filename and path is valid; false otherwise.

To top