Skip to content

StorageInformation Class

Naveen Dharmathunga edited this page Jan 19, 2026 · 1 revision

StorageInformation Class

Provides an abstract base for accessing and representing platform-specific information about a file or storage item, including attributes, size, timestamps, and ownership details.

Namespace: Rheo.Storage.Information

Assembly: Rheo.Storage.dll

Definition

public abstract class StorageInformation : IStorageInformation

Inheritance

Object → StorageInformation

Derived

Constructors

Constructor Description
StorageInformation(String) Initializes a new instance of the StorageInformation class for the specified absolute file path.

Properties

Property Type Description
DisplayName String Gets the display name for the storage item.
Attributes FileAttributes Gets the file attributes of the storage item.
IsReadOnly Boolean Gets a value indicating whether the storage item is read-only.
IsHidden Boolean Gets a value indicating whether the storage item is hidden.
IsSystem Boolean Gets a value indicating whether the storage item is a system file.
IsTemporary Boolean Gets a value indicating whether the storage item is temporary.
Size Int64 Gets the size of the storage item in bytes.
FormattedSize String Gets a human-readable formatted string representing the size.
CreationTime DateTime Gets the creation time of the storage item.
LastWriteTime DateTime Gets the last write time of the storage item.
LastAccessTime DateTime Gets the last access time of the storage item.
IsSymbolicLink Boolean Gets a value indicating whether the storage item is a symbolic link.
LinkTarget String Gets the target path of the symbolic link, if applicable.
OwnerSid String Gets the security identifier (SID) of the owner (Windows only).
Icon Icon Gets the icon representing the storage item (Windows only).
OwnerId Int32? Gets the owner user ID (Unix only).
GroupId Int32? Gets the group ID (Unix only).
Mode Int32? Gets the file mode/permissions (Unix only).

Methods

Method Description
GetSizeString(UOM?) Returns a formatted string representation of the size using the specified unit of measurement.
TryGetWindowsStorageInfo(WindowsStorageInfo) Attempts to retrieve storage information specific to Windows systems.
TryGetUnixStorageInfo(UnixStorageInfo) Attempts to retrieve storage information specific to Unix-based systems.

Remarks

This class exposes a unified interface for retrieving storage metadata across different operating systems. It supports properties for common file attributes, symbolic link information, and platform-specific details such as owner identifiers and access modes. Implementations should provide the actual logic for retrieving the file size. Thread safety is ensured for property access. Use derived types to access additional platform-specific features as needed.

Storage information is retrieved asynchronously in the background upon construction to avoid blocking the calling thread.


Constructor Details

StorageInformation(String)

Initializes a new instance of the StorageInformation class for the specified absolute file path.

public StorageInformation(string absolutePath)

Parameters

absolutePath String

The absolute path to the file or directory for which storage information will be retrieved. Cannot be null, empty, or consist only of white-space characters.

Exceptions

ArgumentException

Thrown if absolutePath is null, empty, or consists only of white-space characters.

Remarks

This constructor begins retrieving platform-specific storage information in the background upon initialization. Accessing storage information properties may block until retrieval is complete.


Property Details

DisplayName

Gets the display name for the storage item.

public string DisplayName { get; }

Property Value

String

The display name as provided by Windows Shell, or the file name without extension on other platforms.


Attributes

Gets the file attributes of the storage item.

public FileAttributes Attributes { get; }

Property Value

FileAttributes

The file attributes.


IsReadOnly

Gets a value indicating whether the storage item is read-only.

public bool IsReadOnly { get; }

Property Value

Boolean

true if the storage item has the ReadOnly attribute; otherwise, false.


IsHidden

Gets a value indicating whether the storage item is hidden.

public bool IsHidden { get; }

Property Value

Boolean

true if the storage item has the Hidden attribute; otherwise, false.


IsSystem

Gets a value indicating whether the storage item is a system file.

public bool IsSystem { get; }

Property Value

Boolean

true if the storage item has the System attribute; otherwise, false.


IsTemporary

Gets a value indicating whether the storage item is temporary.

public bool IsTemporary { get; }

Property Value

Boolean

true if the storage item has the Temporary attribute; otherwise, false.


Size

Gets the size of the storage item in bytes.

public abstract long Size { get; }

Property Value

Int64

The size in bytes.

Remarks

This property must be implemented by derived classes.


FormattedSize

Gets a human-readable formatted string representing the size.

public string FormattedSize { get; }

Property Value

String

A formatted size string (e.g., "1.5 MB", "250 KB").


CreationTime

Gets the creation time of the storage item.

public DateTime CreationTime { get; }

Property Value

DateTime

The creation timestamp.


LastWriteTime

Gets the last write time of the storage item.

public DateTime LastWriteTime { get; }

Property Value

DateTime

The last write timestamp.


LastAccessTime

Gets the last access time of the storage item.

public DateTime LastAccessTime { get; }

Property Value

DateTime

The last access timestamp.


IsSymbolicLink

Gets a value indicating whether the storage item is a symbolic link.

public bool IsSymbolicLink { get; }

Property Value

Boolean

true if the item is a symbolic link; otherwise, false.


LinkTarget

Gets the target path of the symbolic link, if applicable.

public string? LinkTarget { get; }

Property Value

String

The target path, or null if not a symbolic link.


OwnerSid

Gets the security identifier (SID) of the owner (Windows only).

public string? OwnerSid { get; }

Property Value

String

The owner SID on Windows, or null on other platforms.


Icon

Gets the icon representing the storage item (Windows only).

public Icon? Icon { get; }

Property Value

Icon

The icon on Windows, or null on other platforms.


OwnerId

Gets the owner user ID (Unix only).

public int? OwnerId { get; }

Property Value

Int32?

The owner UID on Unix systems, or null on other platforms.


GroupId

Gets the group ID (Unix only).

public int? GroupId { get; }

Property Value

Int32?

The group GID on Unix systems, or null on other platforms.


Mode

Gets the file mode/permissions (Unix only).

public int? Mode { get; }

Property Value

Int32?

The file mode on Unix systems, or null on other platforms.


Method Details

GetSizeString(UOM?)

Returns a formatted string representation of the size using the specified unit of measurement.

public string GetSizeString(UOM? uom = null)

Parameters

uom UOM?

The unit of measurement to use. If null, the appropriate unit is selected automatically.

Returns

String

A formatted size string.


TryGetWindowsStorageInfo(WindowsStorageInfo)

Attempts to retrieve storage information specific to Windows systems.

protected bool TryGetWindowsStorageInfo(out WindowsStorageInfo info)

Parameters

info WindowsStorageInfo

When this method returns, contains a WindowsStorageInfo object with Windows-specific storage details if available; otherwise, the default value.

Returns

Boolean

true if Windows storage information was successfully retrieved; otherwise, false.

Remarks

This method does not throw exceptions. If the underlying storage information is not compatible with Windows or an error occurs, the method returns false and info is set to its default value.


TryGetUnixStorageInfo(UnixStorageInfo)

Attempts to retrieve storage information specific to Unix-based systems.

protected bool TryGetUnixStorageInfo(out UnixStorageInfo info)

Parameters

info UnixStorageInfo

When this method returns, contains a UnixStorageInfo structure with the Unix storage information if available; otherwise, the default value.

Returns

Boolean

true if Unix storage information is available and was retrieved successfully; otherwise, false.

Remarks

This method does not throw exceptions. If the underlying storage information is not compatible with Unix systems or an error occurs during retrieval, the method returns false and info is set to its default value.


UOM Enum

Represents units of measurement for data storage sizes.

public enum UOM

Fields

Field Description
Bytes Bytes unit of measurement.
KB Kilobytes unit of measurement.
MB Megabytes unit of measurement.
GB Gigabytes unit of measurement.
TB Terabytes unit of measurement.

Examples

Accessing Basic Storage Information

The following example demonstrates accessing basic storage properties:

using Rheo.Storage.Information;

var fileInfo = new FileInformation(@"C:\Documents\photo.jpg");

Console.WriteLine($"Display Name: {fileInfo.DisplayName}");
Console.WriteLine($"Size: {fileInfo.FormattedSize}");
Console.WriteLine($"Created: {fileInfo.CreationTime}");
Console.WriteLine($"Modified: {fileInfo.LastWriteTime}");
Console.WriteLine($"Is Hidden: {fileInfo.IsHidden}");
Console.WriteLine($"Is Read-Only: {fileInfo.IsReadOnly}");

Checking for Symbolic Links

The following example shows how to work with symbolic links:

using Rheo.Storage.Information;

var fileInfo = new FileInformation(@"C:\Links\shortcut.lnk");

if (fileInfo.IsSymbolicLink)
{
    Console.WriteLine($"This is a symbolic link pointing to: {fileInfo.LinkTarget}");
}
else
{
    Console.WriteLine("This is not a symbolic link.");
}

Working with Platform-Specific Information

The following example demonstrates accessing platform-specific details:

using Rheo.Storage.Information;

var fileInfo = new FileInformation(@"C:\Documents\file.txt");

if (OperatingSystem.IsWindows() && fileInfo.OwnerSid != null)
{
    Console.WriteLine($"Owner SID: {fileInfo.OwnerSid}");
}
else if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) && fileInfo.OwnerId.HasValue)
{
    Console.WriteLine($"Owner UID: {fileInfo.OwnerId}");
    Console.WriteLine($"Group GID: {fileInfo.GroupId}");
    Console.WriteLine($"Mode: {fileInfo.Mode:X}");
}

Thread Safety

Property access is thread-safe. The underlying storage information is retrieved asynchronously but is cached once loaded.

See Also

Clone this wiki locally