File Uploading in Scaffolded Page

Blooming Developer 276 Reputation points
2021-07-09T09:56:26.293+00:00

Hi

In my Scaffolded Create Page i have a option for file upload.
I want to show this uploaded file in my edit page.

In my create page, im creating a folder with name as record ID and the file will be saved into this folder.

        var foldername = NoticeBoard.ID.ToString();
        var DirectoryPath = Path.Combine(_env.WebRootPath, "AdminDocs", foldername);
        if (!System.IO.Directory.Exists(DirectoryPath))
        {
            System.IO.Directory.CreateDirectory(DirectoryPath);
        }

        if (UploadFile != null)
        {                
            var filesave = Path.Combine(_env.WebRootPath, "AdminDocs", NoticeBoard.ID.ToString(), "Doc-" + NoticeBoard.NoticeName  + "_" + UploadFile.FileName);
            using (var stream = System.IO.File.Create(filesave))
            {
                await UploadFile.CopyToAsync(stream);                    
            }
        }

I want to show this uploaded file in Edit Page and Details page with link to open in another tab.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,551 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.