Oakrey.Applications.FileBrowsing.Extended
1.0.1
dotnet add package Oakrey.Applications.FileBrowsing.Extended --version 1.0.1
NuGet\Install-Package Oakrey.Applications.FileBrowsing.Extended -Version 1.0.1
<PackageReference Include="Oakrey.Applications.FileBrowsing.Extended" Version="1.0.1" />
<PackageVersion Include="Oakrey.Applications.FileBrowsing.Extended" Version="1.0.1" />
<PackageReference Include="Oakrey.Applications.FileBrowsing.Extended" />
paket add Oakrey.Applications.FileBrowsing.Extended --version 1.0.1
#r "nuget: Oakrey.Applications.FileBrowsing.Extended, 1.0.1"
#:package Oakrey.Applications.FileBrowsing.Extended@1.0.1
#addin nuget:?package=Oakrey.Applications.FileBrowsing.Extended&version=1.0.1
#tool nuget:?package=Oakrey.Applications.FileBrowsing.Extended&version=1.0.1
Oakrey.Applications.FileBrowsing.Extended
An extended file browsing library that adds file management operations to the base FileBrowsing service. Provides functionality for creating, deleting, editing files, and opening folders with built-in user prompts for confirmations and error handling.
Features
Extended File Operations
- Create New Files: Create new files with customizable templates
- Delete Files: Delete selected files with confirmation prompts
- Edit Files: Open selected files in their default editor
- Open Folder: Open Windows Explorer with the selected file highlighted
User Interaction
- Integrated Prompts: Built-in user prompts for confirmations and errors
- Error Handling: Comprehensive error handling with user notifications
- Confirmation Dialogs: Safety confirmations before destructive operations
File Reloading
- Manual Reload: Refresh the file list on demand
- Selective Reload: Reload and select a specific file
- Automatic Selection: Maintains file selection after reload
Template Support
- New File Templates: Customizable templates for new file creation
- File Type Specific: Different templates for different file types
- External Template Files: Load templates from external files
Built on Base Service
- Extends
FileBrowsingServicewith additional functionality - Maintains all base features (reactive selection, persistence, etc.)
- Compatible with all base service features
Installation
You can install the package via NuGet Package Manager, Package Manager Console or the .NET CLI.
NuGet Package Manager
- Open your project in Visual Studio.
- Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution....
- Search for
Oakrey.Applications.FileBrowsing.Extendedand click Install.
.NET CLI
Run the following command in your terminal:
dotnet add package Oakrey.Applications.FileBrowsing.Extended
Package Manager Console
Run the following command in your Package Manager Console:
Install-Package Oakrey.Applications.FileBrowsing.Extended
Prerequisites
This package requires:
- Oakrey.Applications.FileBrowsing - Base file browsing functionality
- Oakrey.Applications.UserPrompts.Abstractions - For user interaction prompts
Usage Examples
Basic Setup with Dependency Injection
using Microsoft.Extensions.DependencyInjection;
using Oakrey.Applications.FileBrowsing.Extended;
using Oakrey.Applications.UserPrompts.Windows;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Register user prompts (required for extended service)
services.AddUserPromptsService();
// Register extended file browsing settings
services.AddSingleton<IFileExtendedBrowsingServiceSettings,
MyExtendedFileSettings>();
// Register extended file browsing service
services.AddSingleton<IExtendedFileBrowsingService,
ExtendedFileBrowsingService>();
// Can also be registered as both interfaces
services.AddSingleton<IFileBrowsingService, IExtendedFileBrowsingService,
ExtendedFileBrowsingService>();
}
}
Custom Settings with Template
using Oakrey.Applications.FileBrowsing;
using Oakrey.Applications.FileBrowsing.Extended;
using Oakrey.Applications.Settings;
public class JsonFileSettings : FileBrowsingServiceSettingsBase,
IFileExtendedBrowsingServiceSettings
{
public JsonFileSettings(ISettingsService<JsonFileSettings> settingsService)
: base(settingsService)
{
}
public override string FileExtension => "json";
public override string SearchPattern => "*.json";
public string NewFileTemplate => @"{
""name"": ""New File"",
""version"": ""1.0.0"",
""data"": {}
}";
}
Creating New Files
using Oakrey.Applications.FileBrowsing.Extended;
public class DocumentManager
{
private readonly IExtendedFileBrowsingService _fileBrowser;
public DocumentManager(IExtendedFileBrowsingService fileBrowser)
{
_fileBrowser = fileBrowser;
}
public async Task CreateNewDocumentAsync(string fileName)
{
// Creates a new file with the configured template
// Shows error if file already exists
await _fileBrowser.CreateNewFile(fileName, CancellationToken.None);
// The new file is automatically selected after creation
Console.WriteLine($"Created: {_fileBrowser.SelectedFile?.Name}");
}
}
Deleting Files with Confirmation
public class FileManager
{
private readonly IExtendedFileBrowsingService _fileBrowser;
public FileManager(IExtendedFileBrowsingService fileBrowser)
{
_fileBrowser = fileBrowser;
}
public async Task DeleteCurrentFileAsync()
{
// Shows confirmation dialog before deleting
// Automatically handles errors and shows user prompts
await _fileBrowser.DeleteSelectedFile(CancellationToken.None);
// If deletion succeeded, first available file is selected
if (_fileBrowser.SelectedFile != null)
{
Console.WriteLine($"Now selected: {_fileBrowser.SelectedFile.Name}");
}
}
}
Opening Files in Default Editor
public async Task EditCurrentFileAsync()
{
// Opens the selected file in its default application
// For .txt files, opens in Notepad
// For .json files, opens in default JSON editor, etc.
await _fileBrowser.EditSelectedFile(CancellationToken.None);
// Shows error prompt if file cannot be opened
}
Opening File Location in Explorer
public async Task ShowFileInExplorerAsync()
{
// Opens Windows Explorer with the selected file highlighted
await _fileBrowser.OpenFolder(CancellationToken.None);
// Useful for "Show in Folder" functionality
}
Reloading File List
public class FileWatcher
{
private readonly IExtendedFileBrowsingService _fileBrowser;
public FileWatcher(IExtendedFileBrowsingService fileBrowser)
{
_fileBrowser = fileBrowser;
}
public void RefreshFiles()
{
// Reload all files and maintain current selection
_fileBrowser.Reload();
Console.WriteLine($"Reloaded {_fileBrowser.AvailableFiles.Count} files");
}
public void RefreshAndSelect(FileInfo fileToSelect)
{
// Reload files and select a specific one
_fileBrowser.Reload(fileToSelect);
Console.WriteLine($"Selected: {_fileBrowser.SelectedFile?.Name}");
}
}
Complete WPF ViewModel Example
using Oakrey.Applications.FileBrowsing.Extended;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
public class FileManagerViewModel
{
private readonly IExtendedFileBrowsingService _fileBrowser;
public FileManagerViewModel(IExtendedFileBrowsingService fileBrowser)
{
_fileBrowser = fileBrowser;
CreateFileCommand = new AsyncRelayCommand(CreateFileAsync);
DeleteFileCommand = new AsyncRelayCommand(
DeleteFileAsync,
() => _fileBrowser.SelectedFile != null);
EditFileCommand = new AsyncRelayCommand(
EditFileAsync,
() => _fileBrowser.SelectedFile != null);
OpenFolderCommand = new AsyncRelayCommand(
OpenFolderAsync,
() => _fileBrowser.SelectedFile != null);
RefreshCommand = new RelayCommand(Refresh);
}
public IExtendedFileBrowsingService FileBrowser => _fileBrowser;
public IAsyncRelayCommand CreateFileCommand { get; }
public IAsyncRelayCommand DeleteFileCommand { get; }
public IAsyncRelayCommand EditFileCommand { get; }
public IAsyncRelayCommand OpenFolderCommand { get; }
public ICommand RefreshCommand { get; }
private async Task CreateFileAsync()
{
// In a real app, you'd prompt for the filename
string newFileName = $"NewFile_{DateTime.Now:yyyyMMdd_HHmmss}.json";
await _fileBrowser.CreateNewFile(newFileName, CancellationToken.None);
}
private async Task DeleteFileAsync()
{
await _fileBrowser.DeleteSelectedFile(CancellationToken.None);
// Refresh command states
DeleteFileCommand.NotifyCanExecuteChanged();
EditFileCommand.NotifyCanExecuteChanged();
OpenFolderCommand.NotifyCanExecuteChanged();
}
private async Task EditFileAsync()
{
await _fileBrowser.EditSelectedFile(CancellationToken.None);
}
private async Task OpenFolderAsync()
{
await _fileBrowser.OpenFolder(CancellationToken.None);
}
private void Refresh()
{
_fileBrowser.Reload();
}
}
DBC Files Example (from Demo Application)
using Oakrey.Applications.FileBrowsing;
using Oakrey.Applications.FileBrowsing.Extended;
using Oakrey.Applications.Settings;
public class DbcExtendedFileBrowsingServiceSettings
: FileBrowsingServiceSettingsBase, IFileExtendedBrowsingServiceSettings
{
public DbcExtendedFileBrowsingServiceSettings(
ISettingsService<DbcExtendedFileBrowsingServiceSettings> settingsService)
: base(settingsService)
{
}
public override string FileExtension => "dbc";
public override string SearchPattern => "*.dbc";
public string NewFileTemplate
{
get
{
// Load template from external file
string templatePath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"dbcNew.txt");
if (!File.Exists(templatePath))
{
return "VERSION \"\"\n\nNS_ :\n\nBS_:\n\nBU_:\n";
}
return File.ReadAllText(templatePath);
}
}
}
// In DI configuration
services.AddSingleton<IFileExtendedBrowsingServiceSettings,
DbcExtendedFileBrowsingServiceSettings>();
services.AddSingleton<IFileBrowsingService, IExtendedFileBrowsingService,
ExtendedFileBrowsingService>();
Error Handling
public class SafeFileManager
{
private readonly IExtendedFileBrowsingService _fileBrowser;
public SafeFileManager(IExtendedFileBrowsingService fileBrowser)
{
_fileBrowser = fileBrowser;
}
public async Task CreateFileWithValidationAsync(string fileName)
{
// Validate filename
if (string.IsNullOrWhiteSpace(fileName))
{
Console.WriteLine("Invalid filename");
return;
}
// The service automatically shows error prompts for:
// - File already exists
// - Directory doesn't exist (creates it automatically)
// - Permission errors
// - Any other I/O errors
await _fileBrowser.CreateNewFile(fileName, CancellationToken.None);
}
public async Task DeleteWithCancellationAsync(CancellationToken ct)
{
try
{
// Respects cancellation token
await _fileBrowser.DeleteSelectedFile(ct);
}
catch (OperationCanceledException)
{
Console.WriteLine("Delete operation cancelled");
}
}
}
File Watcher Integration
public class FileSystemWatcher
{
private readonly IExtendedFileBrowsingService _fileBrowser;
private readonly FileSystemWatcher _watcher;
public FileSystemWatcher(
IExtendedFileBrowsingService fileBrowser,
IFileExtendedBrowsingServiceSettings settings)
{
_fileBrowser = fileBrowser;
_watcher = new FileSystemWatcher(settings.FolderPath)
{
Filter = settings.SearchPattern,
EnableRaisingEvents = true
};
_watcher.Created += (s, e) => _fileBrowser.Reload();
_watcher.Deleted += (s, e) => _fileBrowser.Reload();
_watcher.Renamed += (s, e) => _fileBrowser.Reload();
}
}
API Reference
IExtendedFileBrowsingService
Extends IFileBrowsingService with additional methods:
| Method | Parameters | Description |
|---|---|---|
CreateNewFile |
string name, CancellationToken ct |
Creates a new file with the configured template |
DeleteSelectedFile |
CancellationToken ct |
Deletes the selected file with confirmation |
EditSelectedFile |
CancellationToken ct |
Opens the selected file in default editor |
OpenFolder |
CancellationToken ct |
Opens Explorer with file highlighted |
Reload() |
None | Reloads file list, maintains selection |
Reload(FileInfo) |
FileInfo fileInfo |
Reloads and selects specific file |
IFileExtendedBrowsingServiceSettings
Extends IFileBrowsingServiceSettings with:
| Property | Type | Description |
|---|---|---|
NewFileTemplate |
string |
Template content for new files |
ExtendedFileBrowsingService
Extends FileBrowsingService with file management operations:
- Inherits all base service functionality
- Adds file creation, deletion, editing capabilities
- Integrates with user prompt system for confirmations
- Handles errors gracefully with user notifications
Features in Detail
Create New File
- Validates filename uniqueness
- Creates directory if it doesn't exist
- Uses configured template
- Automatically selects new file
- Shows error prompts on failure
Delete File
- Requires file to be selected
- Shows confirmation dialog ("Are you sure?")
- Handles cancellation properly
- Selects next available file after deletion
- Shows error prompts on failure
Edit File
- Opens file in default application
- Uses Windows shell execute
- Logs process ID for tracking
- Shows error prompts on failure
Open Folder
- Opens Windows Explorer
- Highlights the selected file
- Uses
explorer.exe /selectcommand - Shows error prompts on failure
Reload Operations
- Refreshes file list from disk
- Can maintain current selection
- Can select specific file after reload
- Raises property changed events
Architecture
Class Hierarchy
IFileBrowsingService
?
IExtendedFileBrowsingService (extends)
?
ExtendedFileBrowsingService (implements)
?
uses
?
IFileExtendedBrowsingServiceSettings
?
YourCustomSettings (implements)
Dependencies
- Base Service:
FileBrowsingServicefor core browsing - User Prompts:
IUserPrompterfor user interaction - Settings:
IFileExtendedBrowsingServiceSettingsfor configuration
When to Use
Use FileBrowsing.Extended when:
- You need file management operations (create, delete, edit)
- You want built-in user confirmations
- You need to open files in their default editor
- You want "Show in Folder" functionality
- You need file list reloading
Use base FileBrowsing when:
- You only need file selection/browsing
- You want minimal dependencies
- You'll implement custom file operations
Requirements
- .NET 10 or higher
- Windows platform (for Explorer integration)
- Oakrey.Applications.FileBrowsing
- Oakrey.Applications.UserPrompts.Abstractions
Project Information
- Author: Oakrey
- Company: Oakrey
- License: MIT
- Repository: Git Repository
- Project URL: Project Website
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- Oakrey.Applications.FileBrowsing (>= 1.0.1)
- Oakrey.Applications.UserPrompts (>= 1.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Oakrey.Applications.FileBrowsing.Extended:
| Package | Downloads |
|---|---|
|
Oakrey.Applications.FileParsing.DBC
Specialized file parsing library for DBC (CAN database) files. Built on FileParsing framework with automatic parsing into DbcMatrix objects, reactive updates, and extended file management. Features CAN message/signal access, template support, and seamless integration with Oakrey.DBC parser. |
|
|
Oakrey.Applications.FileParsing.LDF
Specialized file parsing library for LDF (LIN Description File) files. Built on FileParsing framework with automatic parsing into LdfMatrix objects, reactive updates, and extended file management. Features LIN frame/signal access, schedule tables, template support, and seamless integration with Oakrey.LDF parser. |
GitHub repositories
This package is not used by any popular GitHub repositories.