File Upload with ASP.NET Core MVC

preview_player
Показать описание
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
DESCRIPTION:
File Upload is the process of uploading files from the user’s system to the web application’s storage. ASP.NET Core MVC actions support uploading one or more files using simple model binding, and in this video, we are going to show you how to do that.
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
LINKS MENTIONED IN THE VIDEO
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
FOLLOW US ON SOCIAL MEDIA!
Рекомендации по теме
Комментарии
Автор

Thank you all for watching and for your support.

CodeMaze
Автор

Great video, no philosophy, right into the pocket! Keep doing great tutorials!

CaLLeNG
Автор

I get UnauthorizedAccessException: Access to the path is denied when I try to add my own directory. I made an /Uploads folder.

harrynewman
Автор

Nice content as always.
I have a question though, what about file validation?
what if users upload malicious scripts?
how do we prevent this?

Time
Автор

Thanks for the great stuff. Is there any better way to save the file instead from controller? Writing some clean code for file upload :) ?

usmanalii
Автор

I am a beginner at MVC been trying to add this code to my project but I cant seem to have a choose file option there's only upload...

nomondengwenya
Автор

Hi good work. My question is DinkToPdf free and used for commercial purposes with unlimited clients?

salimkhanpathan
Автор

File is being copied but only last row inserted into database. Please provide solution.


#region File Upload

if (files != null)
{
Attachment oAttachment = new Attachment();
string CaseNo = oCaseInfo.ID;
string newCaseFilePath = + "\\wwwroot" + "\\uploads\\" + CaseNo;
if //directory create

foreach (var file in files)
{
if (file.Length > 0)
{
//Getting FileName
var fileName =

//Assigning Unique Filename (Guid)
var myUniqueFileName =

//Getting file Extension
var fileExtension = Path.GetExtension(fileName);

// concatenating FileName + FileExtension
var newFileName = String.Concat(myUniqueFileName, fileExtension);

oAttachment.CaseID = oCaseInfo.ID;
oAttachment.AttachmentName = fileName;
= myUniqueFileName + fileExtension;
oAttachment.SetupDate = DateTime.Now;
oAttachment.AttachmentPath = newCaseFilePath;

// Combines two strings into a path.
var filepath = newCaseFilePath + "\\" + newFileName;
//var filepath = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Images")).Root + $@"\{newFileName}";

using (FileStream fs =
{
file.CopyTo(fs);
fs.Flush();
}


}
}
}


#endregion

mazidulislamzahid