SambaFileManager 1.1.4
dotnet add package SambaFileManager --version 1.1.4
NuGet\Install-Package SambaFileManager -Version 1.1.4
<PackageReference Include="SambaFileManager" Version="1.1.4" />
paket add SambaFileManager --version 1.1.4
#r "nuget: SambaFileManager, 1.1.4"
// Install SambaFileManager as a Cake Addin #addin nuget:?package=SambaFileManager&version=1.1.4 // Install SambaFileManager as a Cake Tool #tool nuget:?package=SambaFileManager&version=1.1.4
📁 SambaFileManager
🔹 A .NET 8 library for managing files on a Samba (SMB) server with Dependency Injection support.
📌 Introduction
SambaFileManager is a lightweight .NET 8 library that simplifies reading, writing, and deleting files on Samba (SMB) servers. It provides an easy-to-use API that integrates seamlessly with Dependency Injection (DI).
📌 Key Features:
✔️ Supports reading, writing, and deleting files over an SMB network.
✔️ Integrates with .NET Dependency Injection for easy use in ASP.NET and Console Apps.
✔️ Provides robust error handling and exception management.
✔️ Uses SMBLibrary under the hood for stable and secure SMB communication.
📥 Installation
Install the package via NuGet:
dotnet add package SambaFileManager
Or manually add it to your .csproj
:
<ItemGroup>
<PackageReference Include="SambaFileManager" Version="1.0.0" />
</ItemGroup>
🚀 Quick Start: Using in a Console Application
1️⃣ Setup Dependency Injection
using Microsoft.Extensions.DependencyInjection;
using System;
using SambaFileManager.Interfaces;
using SambaFileManager.Models;
using SambaFileManager.Extensions;
class Program
{
static void Main()
{
// Setup DI container
var sambaSettings = new SambaSettingsBuilder()
.SetServer("192.168.1.100")
.SetShare("storage")
.SetUsername("smbuser")
.SetPassword("smbpassword")
.Build();
var serviceProvider = new ServiceCollection()
.AddSambaFileManagerServices(sambaSettings)
.BuildServiceProvider();
// Resolve the Samba file service
var sambaFileService = serviceProvider.GetRequiredService<ISambaFileService>();
// Define file path
string filePath = "test.txt";
string fileContent = "Hello, Samba File System!";
try
{
// Write a file
Console.WriteLine("Writing file...");
sambaFileService.WriteFile(filePath, fileContent);
Console.WriteLine("File written successfully.");
// Read the file
Console.WriteLine("Reading file...");
string content = sambaFileService.ReadFile(filePath);
Console.WriteLine($"File content: {content}");
// Delete the file
Console.WriteLine("Deleting file...");
sambaFileService.DeleteFile(filePath);
Console.WriteLine("File deleted successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
2️⃣ Expected Output
Writing file...
File written successfully.
Reading file...
File content: Hello, Samba File System!
Deleting file...
File deleted successfully.
🔧 Using in an ASP.NET Core Application
1️⃣ Register the Service in Program.cs
var sambaSettings = builder.Configuration.GetSection("Samba").Get<SambaSettings>();
builder.Services.AddSambaFileManagerServices(sambaSettings);
2️⃣ Inject and Use in a Controller
[ApiController]
[Route("api/files")]
public class FileController : ControllerBase
{
private readonly ISambaFileService _sambaFileService;
public FileController(ISambaFileService sambaFileService)
{
_sambaFileService = sambaFileService;
}
[HttpGet("read")]
public IActionResult ReadFile(string filePath)
{
var content = _sambaFileService.ReadFile(filePath);
return Ok(content);
}
}
🛠 Configuration
You can configure your SMB settings in appsettings.json
:
{
"Samba": {
"Server": "192.168.1.100",
"Share": "SharedFolder",
"Username": "smbuser",
"Password": "smbpassword",
"Domain": ""
}
}
🔗 License
This project is licensed under the MIT License. See the LICENSE file for details.
🙌 Contributing
🎯 Found a bug or have an idea for improvement?
Feel free to open an issue or submit a pull request!
🔗 GitHub Issues
⭐ Support the Project
If you find this package useful, give it a star ⭐ on GitHub and share it with others! 🚀
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- SMBLibrary (>= 1.5.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Initial release of SambaFileManager.
- Supports reading, writing, and deleting files on Samba servers.
- Integrates with .NET 8 Dependency Injection.
- Provides error handling and exception management for SMB connections.