From e5748ec8d587ddd05d6c4e04a9f6acb1d2f9dac4 Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Sun, 20 Sep 2020 14:05:18 +1000 Subject: [PATCH] use the ID for the document filenames --- Pages/Documents/View.cshtml | 3 ++- Pages/Upload.cshtml.cs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Pages/Documents/View.cshtml b/Pages/Documents/View.cshtml index 2daaeec..3817e4d 100644 --- a/Pages/Documents/View.cshtml +++ b/Pages/Documents/View.cshtml @@ -5,6 +5,7 @@ ViewData["Title"] = $"Viewing \"{Model.Document.Title}\""; ViewData["SlimNavbar"] = true; ViewData["NoMainPadding"] = true; + string path = $"/Content/{Model.Document.ID}.pdf"; } - \ No newline at end of file + \ No newline at end of file diff --git a/Pages/Upload.cshtml.cs b/Pages/Upload.cshtml.cs index 4b20489..ca186ff 100644 --- a/Pages/Upload.cshtml.cs +++ b/Pages/Upload.cshtml.cs @@ -32,10 +32,10 @@ namespace Snootalogue.Pages { return Page(); } - var filename = WebUtility.HtmlEncode(ud.UploadedFile.FileName); + var id = Document.NewID(_context); // var uploadDirectory = Path.Combine(filename); var uploadDirectory = "wwwroot/Content"; - var destination = Path.Combine(uploadDirectory, filename); + var destination = Path.Combine(uploadDirectory, $"{id}.pdf"); using (var fs = new FileStream(destination, FileMode.Create)) { await ud.UploadedFile.CopyToAsync(fs); @@ -43,14 +43,14 @@ namespace Snootalogue.Pages { // Document d = _context.Document. Document d = new Document { - ID = Document.NewID(_context), + ID = id, Title = ud.Title, Authors = ud.Authors.Split(",").ToList(), Category = ud.Category, Tags = string.IsNullOrWhiteSpace(ud.Tags) ? null : ud.Tags.Split(",").ToList(), Notes = ud.Notes, Read = ud.Read, - Filename = filename + Filename = WebUtility.HtmlEncode(ud.UploadedFile.FileName) }; _context.Document.Add(d);