NOTE:access denied due to not giving file name
var path = Path.Combine(_hostEnvironment.WebRootPath, "Uploads","Messages", MessageID.ToString());
bool basePathExists = System.IO.Directory.Exists(path);
if (!basePathExists) Directory.CreateDirectory(path);
//while upload file you set path as well as filename then you dont get error accessdenied(imp)
var filePath = Path.Combine(path, message.uploadfilename.FileName);
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
message.uploadfilename.CopyTo(fileStream);
}
basic code to upload file based on created id after save imp
https://codewithmukesh.com/blog/file-upload-in-aspnet-core-mvc/
No comments:
Post a Comment