Using FileUltimate in an ASP.NET Core project
To use FileUltimate in an ASP.NET Core Project, do the following in Visual Studio:
Make sure you have added references to FileUltimate assemblies as described here.
Open Program.cs of your project and insert the marked lines:
using GleamTech; using GleamTech.AspNet; using GleamTech.AspNet.Core; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); //---------------------- //Add GleamTech to the ASP.NET Core services container. builder.Services.AddGleamTech(); //---------------------- var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); } //---------------------- //Register GleamTech to the ASP.NET Core HTTP request pipeline. app.UseGleamTech(); //---------------------- app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run();Caution
services.AddGleamTechcallsservices.AddDistributedMemoryCacheandservices.AddSessioninternally and if you need to set a custom cache likeservices.AddStackExchangeRedisCacheor need to callservices.AddSessionwith custom options then place them beforeservices.AddGleamTechso that they become effective.Caution
The order of
app.UseXXXmethods is important soapp.UseGleamTechshould be placed beforeapp.UseStaticFiles,app.UseRoutingandapp.UseEndpoints(or beforeapp.UseMvcfor legacy ASP.NET Core 2.1).If you have a legacy ASP.NET Core project (before .NET 6 minimal hosting model), open Startup.cs of your project and insert the marked lines into
ConfigureServicesandConfiguremethods of yourStartupclass.public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); //---------------------- //Add GleamTech to the ASP.NET Core services container. services.AddGleamTech(); //---------------------- } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } //---------------------- //Register GleamTech to the ASP.NET Core HTTP request pipeline. app.UseGleamTech(); //---------------------- app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }Optionally set FileUltimate's global configuration (if overriding a default value is required). For example, you may want to set the license key.
You can specify the configuration in
appsettings.jsonfile:{ //Set this property only if you have a valid license key, otherwise do not //set it so FileUltimate runs in trial mode. "FileUltimate:LicenseKey": "QQJDJLJP34..." }As you would notice,
FileUltimate:prefix maps toFileUltimateConfiguration.CurrentandFileUltimateWeb:prefix maps toFileUltimateWebConfiguration.Current.Alternatively you can specify the configuration in code, in
Configuremethod of your Startup.cs afterapp.UseGleamTechcall://---------------------- //Register GleamTech to the ASP.NET Core HTTP request pipeline. app.UseGleamTech(() => { //Set this property only if you have a valid license key, otherwise do not //set it so FileUltimate runs in trial mode. FileUltimateConfiguration.Current.LicenseKey = "QQJDJLJP34..."; }); //----------------------Create a new View (eg. Index.cshtml) and insert these lines:
@using GleamTech.AspNet.Core @using GleamTech.FileUltimate.AspNet.UI <!DOCTYPE html> @{ var fileManager = new FileManager { Width = 800, Height = 600, Resizable = true }; var rootFolder = new FileManagerRootFolder { Name = "A Root Folder", Location = "~/App_Data/RootFolder1" }; rootFolder.AccessControls.Add(new FileManagerAccessControl { Path = @"\", AllowedPermissions = FileManagerPermissions.Full }); fileManager.RootFolders.Add(rootFolder); } <html> <head> <title>File Manager</title> @this.RenderHead(fileManager) </head> <body> @this.RenderBody(fileManager) </body> </html>Tip
Alternatively you can add the namespaces globally in Views/_ViewImports.cshtml to avoid adding namespaces in your pages every time.
This will render a FileManager component in the page, which displays one root folder named
A Root Folderwhich points to virtual path~/App_Data/RootFolder1with Full permissions. TheFileManagerRootFolder.Locationproperty can point to a physical/virtual path, a UNC path with specific credentials, a path on Amazon S3 or Azure Blob Storage, a custom location provider.If you need a standalone file uploader component, insert these lines instead:
@using GleamTech.AspNet.Core @using GleamTech.FileUltimate.AspNet.UI <!DOCTYPE html> @{ var fileUploader = new FileUploader { Width = 600, Height = 300, Resizable = true, UploadLocation = "~/App_Data/Uploads" }; } <html> <head> <title>File Uploader</title> @this.RenderHead(fileUploader) </head> <body> @this.RenderBody(fileUploader) </body> </html>