Wednesday, 8 June 2022

fileUpload in asp.net core

 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

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...