Oakrey.Applications.FileBrowsing 1.0.1

dotnet add package Oakrey.Applications.FileBrowsing --version 1.0.1
                    
NuGet\Install-Package Oakrey.Applications.FileBrowsing -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Applications.FileBrowsing" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Applications.FileBrowsing" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Applications.FileBrowsing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Applications.FileBrowsing --version 1.0.1
                    
#r "nuget: Oakrey.Applications.FileBrowsing, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Applications.FileBrowsing@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Applications.FileBrowsing&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.FileBrowsing&version=1.0.1
                    
Install as a Cake Tool

Oakrey.Applications.FileBrowsing

A .NET library for managing file browsing and selection in applications. Provides an abstraction layer for browsing files in directories with support for filtering, search patterns, and reactive file selection tracking.

Features

File Management

  • Directory Browsing: Browse files in specified directories
  • Search Patterns: Filter files using customizable search patterns
  • File Extension Filtering: Target specific file types
  • Recursive Search: Option to include subdirectories

Reactive File Selection

  • Observable Pattern: Track file selection changes with IObservable<FileInfo?>
  • Automatic Persistence: Remember last selected file across sessions
  • Property Change Notifications: Implements INotifyPropertyChanged for data binding

Configurable Settings

  • Customizable Folder Paths: Specify which directories to browse
  • Persistent Settings: Settings saved and restored automatically
  • Folder Path Change Tracking: Observable folder path changes

Built on Settings Service

  • Integrates with Oakrey.Applications.Settings for persistence
  • Thread-safe settings management
  • Strongly-typed configuration

Easy Extension

  • Abstract base classes for custom implementations
  • Interface-based design for testability
  • Support for specialized file browsers (DBC, INI, etc.)

Installation

You can install the package via NuGet Package Manager, Package Manager Console or the .NET CLI.

NuGet Package Manager

  1. Open your project in Visual Studio.
  2. Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution....
  3. Search for Oakrey.Applications.FileBrowsing and click Install.

.NET CLI

Run the following command in your terminal:

dotnet add package Oakrey.Applications.FileBrowsing

Package Manager Console

Run the following command in your Package Manager Console:

Install-Package Oakrey.Applications.FileBrowsing

Prerequisites

This package requires:

  • Oakrey.Applications.Settings - For settings persistence

Usage Examples

Basic File Browsing Service

using Oakrey.Applications.FileBrowsing;
using Oakrey.Applications.Settings;

// Create custom settings for your file type
public class MyDocumentSettings : FileBrowsingServiceSettingsBase
{
    public MyDocumentSettings(ISettingsService<MyDocumentSettings> settingsService) 
        : base(settingsService)
    {
    }

    public override string FileExtension => "txt";
    public override string SearchPattern => "*.txt";
}

// Use the file browsing service
public class DocumentManager
{
    private readonly IFileBrowsingService _fileBrowser;

    public DocumentManager(IFileBrowsingService fileBrowser)
    {
        _fileBrowser = fileBrowser;
        
        // Subscribe to file selection changes
        _fileBrowser.SelectedFileChanged.Subscribe(fileInfo =>
        {
            if (fileInfo != null)
            {
                Console.WriteLine($"Selected: {fileInfo.Name}");
                LoadDocument(fileInfo.FullName);
            }
        });
    }

    public void LoadDocument(string path)
    {
        // Load your document
    }
}

Dependency Injection Setup

using Microsoft.Extensions.DependencyInjection;
using Oakrey.Applications.FileBrowsing;
using Oakrey.Applications.Settings;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Register settings service
        services.AddSingleton<ISettingsService<MyDocumentSettings>, 
                             SettingsService<MyDocumentSettings>>();
        
        // Register file browsing settings
        services.AddSingleton<IFileBrowsingServiceSettings, MyDocumentSettings>();
        
        // Register file browsing service
        services.AddSingleton<IFileBrowsingService, FileBrowsingService>();
    }
}

Custom File Type Browser (DBC Files Example)

using Oakrey.Applications.FileBrowsing;
using Oakrey.Applications.Settings;

// Settings for DBC files
public class DbcFileBrowsingServiceSettings : FileBrowsingServiceSettingsBase
{
    public DbcFileBrowsingServiceSettings(
        ISettingsService<DbcFileBrowsingServiceSettings> settingsService)
        : base(settingsService)
    {
    }

    public override string FileExtension => "dbc";
    public override string SearchPattern => "*.dbc";
}

// Register in DI
services.AddSingleton<IFileBrowsingServiceSettings, DbcFileBrowsingServiceSettings>();
services.AddSingleton<IFileBrowsingService, FileBrowsingService>();

WPF Data Binding Example

<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:fb="clr-namespace:Oakrey.Applications.FileBrowsing;assembly=Oakrey.Applications.FileBrowsing">
    
    <Window.Resources>
        <fb:PathToNameConverter x:Key="PathToNameConverter"/>
    </Window.Resources>
    
    <Grid>
        
        <ListBox ItemsSource="{Binding FileBrowser.AvailableFiles}"
                 SelectedItem="{Binding FileBrowser.SelectedFile}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        
        
        <TextBlock Text="{Binding FileBrowser.SelectedFile.FullName, 
                         Converter={StaticResource PathToNameConverter}}"/>
    </Grid>
</Window>

ViewModel Integration

using Oakrey.Applications.FileBrowsing;
using System.ComponentModel;

public class MainViewModel : INotifyPropertyChanged
{
    private readonly IFileBrowsingService _fileBrowser;

    public MainViewModel(IFileBrowsingService fileBrowser)
    {
        _fileBrowser = fileBrowser;
        
        // Subscribe to file changes
        _fileBrowser.SelectedFileChanged.Subscribe(OnFileSelected);
    }

    public IFileBrowsingService FileBrowser => _fileBrowser;

    public List<FileInfo> Files => _fileBrowser.AvailableFiles;
    
    public FileInfo? CurrentFile
    {
        get => _fileBrowser.SelectedFile;
        set
        {
            _fileBrowser.SelectedFile = value;
            OnPropertyChanged(nameof(CurrentFile));
        }
    }

    private void OnFileSelected(FileInfo? fileInfo)
    {
        if (fileInfo != null)
        {
            // Handle file selection
            Console.WriteLine($"File selected: {fileInfo.FullName}");
        }
    }

    public event PropertyChangedEventHandler? PropertyChanged;
    
    protected void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

Changing Folder Path Dynamically

public class FileManagerService
{
    private readonly IFileBrowsingService _fileBrowser;
    private readonly IFileBrowsingServiceSettings _settings;

    public FileManagerService(
        IFileBrowsingService fileBrowser,
        IFileBrowsingServiceSettings settings)
    {
        _fileBrowser = fileBrowser;
        _settings = settings;
        
        // Subscribe to folder path changes
        _settings.FolderPathChanged.Subscribe(OnFolderChanged);
    }

    public void ChangeBrowsingFolder(string newPath)
    {
        if (Directory.Exists(newPath))
        {
            // This will trigger file list refresh automatically
            _settings.FolderPath = newPath;
        }
    }

    private void OnFolderChanged(string newPath)
    {
        Console.WriteLine($"Now browsing: {newPath}");
        Console.WriteLine($"Found {_fileBrowser.AvailableFiles.Count} files");
    }
}

Including Subdirectories

public class RecursiveFileBrowsingSettings : FileBrowsingServiceSettingsBase
{
    public RecursiveFileBrowsingSettings(
        ISettingsService<RecursiveFileBrowsingSettings> settingsService)
        : base(settingsService)
    {
        // Enable recursive search
        IncludeSubFolders = true;
    }

    public override string FileExtension => "json";
    public override string SearchPattern => IncludeSubFolders ? "**/*.json" : "*.json";
}

Complete Application Example

using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using Oakrey.Applications.FileBrowsing;
using Oakrey.Applications.Settings;

public partial class App : Application
{
    private IServiceProvider _serviceProvider;

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        var services = new ServiceCollection();
        
        // Configure settings
        services.AddSingleton<ISettingsService<MyFileSettings>, 
                             SettingsService<MyFileSettings>>();
        
        // Configure file browsing
        services.AddSingleton<IFileBrowsingServiceSettings, MyFileSettings>();
        services.AddSingleton<IFileBrowsingService, FileBrowsingService>();
        
        // Configure view models
        services.AddTransient<MainViewModel>();
        
        _serviceProvider = services.BuildServiceProvider();
        
        var mainWindow = new MainWindow
        {
            DataContext = _serviceProvider.GetRequiredService<MainViewModel>()
        };
        
        mainWindow.Show();
    }
}

Testing with Mock Service

using Oakrey.Applications.FileBrowsing;

public class MockFileBrowsingService : IFileBrowsingService
{
    public List<FileInfo> AvailableFiles { get; set; } = new();
    
    public FileInfo? SelectedFile { get; set; }
    
    public IObservable<FileInfo?> SelectedFileChanged => 
        Observable.Return(SelectedFile);
}

// In your tests
[Fact]
public void TestDocumentLoading()
{
    var mockBrowser = new MockFileBrowsingService
    {
        AvailableFiles = new List<FileInfo>
        {
            new FileInfo("test1.txt"),
            new FileInfo("test2.txt")
        }
    };
    
    var service = new DocumentService(mockBrowser);
    mockBrowser.SelectedFile = mockBrowser.AvailableFiles[0];
    
    // Assert your expectations
}

API Reference

IFileBrowsingService

Property Type Description
AvailableFiles List<FileInfo> List of files matching the search criteria
SelectedFile FileInfo? Currently selected file (persisted)
SelectedFileChanged IObservable<FileInfo?> Observable for file selection changes

IFileBrowsingServiceSettings

Property Type Description
FileExtension string File extension to filter (e.g., "txt")
SearchPattern string Search pattern (e.g., "*.txt")
FolderPath string Directory to browse
FolderPathChanged IObservable<string> Observable for folder changes
IncludeSubFolders bool Include subdirectories in search
LastSelectedFile string Path of last selected file (persisted)

FileBrowsingServiceSettingsBase

Abstract base class for creating custom file browsing settings:

  • Inherits from SettingsBase
  • Implements IFileBrowsingServiceSettings
  • Provides reactive folder path changes
  • Handles settings persistence automatically

Architecture

Class Hierarchy

IFileBrowsingService
    ?
FileBrowsingService (implements IFileBrowsingService)
    ?
    uses
    ?
IFileBrowsingServiceSettings
    ?
FileBrowsingServiceSettingsBase (abstract)
    ?
    inherits
    ?
YourCustomSettings (concrete implementation)

Key Features

  • Reactive Design: Uses System.Reactive for observable patterns
  • Settings Integration: Automatically persists user preferences
  • MVVM Support: Implements INotifyPropertyChanged for WPF data binding
  • Disposable: Proper cleanup of subscriptions and observables
  • Extensible: Easy to create specialized file browsers

Extension Packages

  • Oakrey.Applications.FileBrowsing.Extended - Extended browsing with categories
  • Oakrey.Applications.FileBrowsing.DBC - Specialized for DBC files
  • Oakrey.Applications.FileBrowsing.Ini - Specialized for INI files

Requirements

  • .NET 10 or higher
  • Oakrey.Applications.Settings

Project Information

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to improve the package.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Oakrey.Applications.FileBrowsing:

Package Downloads
Oakrey.Applications.FileParsing

Abstract framework for parsing files with automatic loading and reactive observable patterns. Provides base classes for building file-based services that automatically parse and monitor file changes. Features integration with file browsing, error handling with user prompts, and pre-loading support.

Oakrey.Applications.FileBrowsing.Extended

Extended file browsing library with file management operations. Adds create, delete, edit file capabilities with built-in user prompts and confirmations. Features customizable file templates, Windows Explorer integration, and comprehensive error handling. Extends Oakrey.Applications.FileBrowsing.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 79 3/13/2026
1.0.0 77 3/11/2026