Show / Hide Table of Contents

    Class PathHelper

    Helpers for working with file/folder paths.

    Inheritance
    System.Object
    PathHelper
    Namespace: Kros.IO
    Assembly: Kros.Utils.dll
    Syntax
    public static class PathHelper

    Methods

    BuildPath(String[])

    Joins parts parts to one string, representing path to a file/folder.

    Declaration
    public static string BuildPath(params string[] parts)
    Parameters
    Type Name Description
    System.String[] parts

    Path parts.

    Returns
    Type Description
    System.String

    Created path.

    Remarks

    The method works similarly as standard .NET method System.IO.Path.Combine(System.String[]), with some different details:

    Exceptions
    Type Condition
    System.ArgumentNullException

    The value of parts or any of its item is null.

    System.ArgumentException

    Any of the item in parts contains invalid characters defined in System.IO.Path.GetInvalidPathChars.

    GetTempPath()

    Returns path to system temporary folder (System.IO.Path.GetTempPath) without trailing directory separator.

    Declaration
    public static string GetTempPath()
    Returns
    Type Description
    System.String

    IsNetworkPath(String)

    Checks, if specified path is network share path. The path is considered network share path, if it begins with \.

    Declaration
    public static bool IsNetworkPath(string path)
    Parameters
    Type Name Description
    System.String path

    Checked path.

    Returns
    Type Description
    System.Boolean

    true if path is network share path, false otherwise.

    ReplaceInvalidPathChars(String)

    Replaces invalid characters in pathName with dash (-). If there are several succesive invalid characters, they all are replaced only by one dash.

    Declaration
    public static string ReplaceInvalidPathChars(string pathName)
    Parameters
    Type Name Description
    System.String pathName

    Input path.

    Returns
    Type Description
    System.String
    Remarks

    ReplaceInvalidPathChars(String, String)

    Replaces invalid characters in pathName with replacement. If there are several succesive invalid characters, they all are replaced only by one replacement.

    Declaration
    public static string ReplaceInvalidPathChars(string pathName, string replacement)
    Parameters
    Type Name Description
    System.String pathName

    Input path.

    System.String replacement

    Value, by which are replaced invalid path charactes. If the value is null, empty stirng is used, so invalid characters are removed.

    Returns
    Type Description
    System.String

    String with invalid path characters replaced. If input pathName is null, empty string is returned.

    Remarks

    Replaced are all characters in System.IO.Path.GetInvalidFileNameChars and System.IO.Path.GetInvalidPathChars.

    Back to top KROS a.s.