Sam.FileTableFramework 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sam.FileTableFramework --version 1.0.1                
NuGet\Install-Package Sam.FileTableFramework -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="Sam.FileTableFramework" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sam.FileTableFramework --version 1.0.1                
#r "nuget: Sam.FileTableFramework, 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.
// Install Sam.FileTableFramework as a Cake Addin
#addin nuget:?package=Sam.FileTableFramework&version=1.0.1

// Install Sam.FileTableFramework as a Cake Tool
#tool nuget:?package=Sam.FileTableFramework&version=1.0.1                

Building a File Management Application with ASP.NET Core and SQL Server FileTable

Introduction

In today's digital world, effective file management is crucial for individuals and organizations alike. Developing a file management application can help streamline file organization and improve accessibility. In this article, we will explore the intricacies and implementation steps of building a file management application using ASP.NET Core and SQL Server FileTable.

Getting Started

  1. You'll want to enable SQL Server FILESTREAM. Follow the instructions in this link for the necessary guidance on activation.

  2. To install the Sam.File Table Framework package, simply use the following command

    • .NET CLI

      dotnet add package Sam.FileTableFramework --version 1.0.1
      
    • Package Manager

      NuGet\Install-Package Sam.FileTableFramework -Version 1.0.1
      
    • Package Reference

      <PackageReference Include="Sam.FileTableFramework" Version="1.0.1" />
      
    • Paket CLI

      paket add Sam.FileTableFramework --version 1.0.1
      
  3. Create your DbContext by inheriting from FileTableDbContext. Then, define a FtDbSet property for your tables.

    using Sam.FileTableFramework.Context;
    
    namespace Sam.Persistence
    {
        public class DatabaseContext: FileTableDBContext
        {
            public FtDbSet Table1 { get; set; }
            public FtDbSet Table2 { get; set; }
            public FtDbSet Table3 { get; set; }
        }
    }
    

    You can have your advanced FtDbSet, for this, refer to this link

  4. Register your DatabaseContext class in Startup

    // ...
    builder.Services.AddFileTableDBContext<DatabaseContext>(o =>
        o.ConnectionString = "Data Source =.; Initial Catalog = DatabaseName; Integrated Security = true");
    // ...
    
    
  5. You can create the database by adding the following code when the project is running

    // ...
    using (var scope = app.Services.CreateScope())
    {
        var services = scope.ServiceProvider;
    
        services.GetRequiredService<DatabaseContext>().Migrate();
    }
    // ...
    
  6. Now you can inject DatabaseContext in your classes and use your tables, for example, see the source code below

    using Microsoft.AspNetCore.Mvc;
    using Sam.Persistence;
    using System.Net.Mime;
    
    namespace Sam.EndPoint.WebApi.Controllers
    {
        [ApiController]
        [Route("[controller]")]
        public class FileController(DatabaseContext databaseContext) : ControllerBase
        {
    
            [HttpGet("GetPaged/{page}/{pageCount}")]
            public async Task<IActionResult> GetPaged(int page, int pageCount)
            {
                return Ok(await databaseContext.Table1.GetPagedListAsync(page, pageCount));
            }
    
            [HttpGet("GetAll")]
            public async Task<IActionResult> GetAll()
            {
                return Ok(await databaseContext.Table1.GetAllAsync());
            }
    
            [HttpGet("Count")]
            public async Task<IActionResult> Count()
            {
                return Ok(await databaseContext.Table1.Count());
            }
    
            [HttpGet("Download/{name}")]
            public async Task<IActionResult> Download(string name)
            {
                var result = await databaseContext.Table1.FindByNameAsync(name);
    
                if (result is null)
                    return NotFound(name);
    
                return File(result.file_stream!, MediaTypeNames.Application.Octet, result.name);
            }
    
            [HttpPost("Upload")]
            public async Task<IActionResult> Upload(IFormFile file)
            {
                var fileName = Guid.NewGuid() + file.FileName[file.FileName.LastIndexOf(".", StringComparison.Ordinal)..];
                var stream = file.OpenReadStream();
                return Ok(await databaseContext.Table1.CreateAsync(fileName, stream));
            }
    
            [HttpDelete("Delete")]
            public async Task<IActionResult> Delete(string name)
            {
                return Ok(await databaseContext.Table1.RemoveByNameAsync(name));
            }
        }
    }
    

Conclusion

In this article, we delved into creating a file management application using ASP.NET Core and SQL Server FileTable. This application provides functionalities for organizing and managing files in a web environment. Leveraging modern technologies and tools like FileTable, we were able to build a secure, reliable, and high-performance application.

Support

If you are having problems, please let me know by raising a new issue.

License

This project is licensed with the MIT license.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 114 7/31/2024
2.0.0 106 6/22/2024
1.0.1 92 5/1/2024