File upload in asp net core mvc

  Рет қаралды 189,574

kudvenkat

kudvenkat

Күн бұрын

Пікірлер: 150
@amitghosh1983
@amitghosh1983 4 жыл бұрын
There is a breaking change in core 3.1 for the IForm class, above is Core 2.1. make sure you add asp-action="Create" enctype="multipart/form-data" to the Create View to populate the path. After that small change, It's working like a charm for me. Kudos to Venkat, you rock!!
@Nermin913
@Nermin913 5 жыл бұрын
Awesome video. Very informative, thank you! Just a quick comment: When you use the CopyTo() method from the IFormFile interface, you instantiate a new filestream object as the parameter, resulting in you not closing the filestream object. This will give SystemIO exceptions later on if you want to delete those images from the server. A simple fix is just to instantiate the filestream object before using the CopyTo() method, and thereafter calling the Close() method: FileStream fs = new FileStream(filePath, FileMode.Create); model.Image.CopyTo(fs); fs.Close();
@admiremhlaba1192
@admiremhlaba1192 5 жыл бұрын
Thank you for the pointer, alternatively you could achieve the same by doing this using(FileStream fs = new FileStream(filePath, FileMode.Create)) { model.Image.CopyTo(fs); }
@nikhilchoubisa8134
@nikhilchoubisa8134 4 жыл бұрын
You guys saved me. I was uploading an excel file using reference of this video and later while reading that file I got following error : "the process cannot access the file because it is being used by another process". After applying this help my code worked. Thank you guys. :)
@applemanforever
@applemanforever 5 жыл бұрын
Where the hell did this guy learn all this stuff from. Absolute Monster at ASP.NET Core
@naveenbaghel2936
@naveenbaghel2936 4 жыл бұрын
That's what i am wondering from very first day....And if we come to know we can also do magic.
@danishmalak9221
@danishmalak9221 4 жыл бұрын
From microsoft asp.net core documentations
@Abhimanyukumar-vb8bz
@Abhimanyukumar-vb8bz 4 жыл бұрын
we can also use "col-sm-4" class wrapping div element with class "card -m-3" to restrict 3 columns in one row instead of hardcoding the style attribute with min and max-width like this : @foreach (var Employee in Model) { var photoPath = "~/Images/" + (Employee.PhotoPath ?? "banner1.jpg"); @Employee.Name View Edit Delete }
@husam-ebish
@husam-ebish 5 жыл бұрын
***To Delete the old image when uploadin a new one:*** ***Interface: IPhotoRepository.cs:*** public interface IPhotoRepository { string GetOldUserPhoto(string userId); } Entity Class: EFPhotoRepository.cs (or you can name it as you want): public class EFPhotoRepository : IPhotoRepository { private readonly AppDbContext context; public EFPhotoRepository(AppDbContext context) { this.context = context; } public string GetOldUserPhoto(string userId) { var user = context.Users.SingleOrDefault(u => u.Id == userId); var userPhotoPath = user.PhotoPath; return userPhotoPath; } } ***Inject the IPhotoRepository to the Controller, do not forget the constructor & the private fields: *** ***(in my case i injected all services I needed):*** private readonly UserManager userManager; private readonly SignInManager signInManager; private readonly RoleManager roleManager; private readonly IHostingEnvironment hostingEnvironment; private readonly IPhotoRepository photoRepository; public AccountController(UserManager userManager, SignInManager signInManager, RoleManager roleManager, IHostingEnvironment hostingEnvironment, IPhotoRepository photoRepository) { this.userManager = userManager; this.signInManager = signInManager; this.roleManager = roleManager; this.hostingEnvironment = hostingEnvironment; this.photoRepository = photoRepository; } ***Implemet your Action*** ***(in my case the Action names "EditProfile" and the ViewModel names "EditUserProfileViewModel"):*** [HttpPost] public async Task EditProfile(EditUserProfileViewModel model) { string uniqueFileName = null; if (model.Photo != null) { string usersPhotosUploadFolder = Path.Combine(hostingEnvironment.WebRootPath, "Users Photos"); var oldPhotoName = photoRepository.GetOldUserPhoto(model.Id); string fullPath = Path.Combine(usersPhotosUploadFolder + "/" + oldPhotoName); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string photoPath = Path.Combine(usersPhotosUploadFolder, uniqueFileName); model.Photo.CopyTo(new FileStream(photoPath, FileMode.Create)); } var user = await userManager.FindByIdAsync(model.Id); if (user == null) { ViewBag.ErrorMessage = $"User with Id: {model.Id} cannot be found"; return View("NotFound"); } else { user.Gender = model.Gender; user.Nationality = model.Nationality; user.City = model.City; user.Country = model.Country; user.PhotoPath = uniqueFileName; var result = await userManager.UpdateAsync(user); if (result.Succeeded) { return RedirectToAction("Profile", "Account", new { id = user.Id }); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return View(model); } } *//* DONT FORGET TO ADD THE IPhotoRepository and EFPhotoRepository TO Sartup.cs *//* ***This is the code:*** services.AddScoped(); ***If the annotation is helpful, don't forget to hit "like" to keep the comment up***
@carlosinigo9225
@carlosinigo9225 4 жыл бұрын
Excellent tutorial! Jquery script wasn't working for me initially, til i double checked it thoroughly and saw i was missing a '.' before 'custom-file-label'. Thank you very much!
@marcioaugusto392
@marcioaugusto392 4 жыл бұрын
You're awesome! As always I love watching your contents and good explanations can mae we learn so much
@MmMm-tg5mq
@MmMm-tg5mq 5 жыл бұрын
very concentrated video, if other guy do this he will need five or more videos.nice and informative video thanks a lot for your efforts and accept my greetings
@alensgallery
@alensgallery 5 жыл бұрын
When I get to 13:00 i need to create a fileName and use GetFilename and include it in a variable because filename property returns the complete path including the filename and the extension. Because of the filename appending, the final image path ends up having more than just the name appended. Am I missing something?? Here is the code change string fileName = Path.GetFileName(model.Photo.FileName); uniqueFileName = Guid.NewGuid().ToString() + "_" + fileName;
@northernouthouse
@northernouthouse 5 жыл бұрын
Yes, I had the exact same error and your recommended code fixed the issue. Thanks!
@AmirKMilbes
@AmirKMilbes 4 жыл бұрын
Instead of writing inline CSS, you should have used class=row and col-md-4 as in example below. 4 + 4 + 4 = 12 -- the bootstrap 12-rows model. But, you are still my great teacher. Thank you for the videos. @foreach (var employee in Model) { var photoPath = "~/images/" + employee.PhotoPath; @employee.Name View Edit Delete }
@dannybradley9346
@dannybradley9346 5 жыл бұрын
I am attempting to use the newest VS2019 and .net core versions. The tutorials are excellent, and I was able to make it all work until the "File upload in asp net core mvc" tutorial; it uses a now-deprecated IHostingEnvironment. At that point, VS recommends IWebHostEnvironment. I tried many things and could not get IWebHostEnvironment to work without errors: "Model bound complex types must not be abstract or value types and must have a parameterless constructor. Alternatively, give the 'hostingEnvironment' parameter a non-null default value.". How to make it work?
@hughcoleman9400
@hughcoleman9400 5 жыл бұрын
I may be using a slightly older version VS2019 and .NET core and this may be just a work around, but when I encountered that error in another tutorial I used the [obsolete] attribute above the class and it worked
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 5 жыл бұрын
Hello Danny - We used IWebHostEnvironment instead of IHostingEnvironment service in Part 16 of Razor Pages Tutorial. Hope this helps. The following page has all the videos, slides and text version in sequence. www.pragimtech.com/courses/asp-net-core-razor-pages-tutorial-for-beginners/
@shrikantnathan6626
@shrikantnathan6626 5 жыл бұрын
In the details view, I am not able to get the values of the model as I am getting the error of "NullReferenceException: Object reference not set to an instance of an object." how to fix this Issue?
@martinsteegh160
@martinsteegh160 4 жыл бұрын
I'm having the same problem, did you find a solution? Thanks in advance!
@hetalchavan9446
@hetalchavan9446 4 жыл бұрын
Getting the same error. Any help is appreciated.
@Fetretim
@Fetretim 2 жыл бұрын
Any Solutions?
@Fetretim
@Fetretim 2 жыл бұрын
Guys my problem solved, i forget to add "this.hostingEnvironment=hostingEnvironment" (hostingEnvironment = our host environment name). When i added this, its fixed.
@mofeedboss9170
@mofeedboss9170 5 жыл бұрын
Thanks so much! I really needed that in my projects, regards!
@bashirmanafikhi
@bashirmanafikhi 5 жыл бұрын
احلى استااذ فينكات الله يجزيك الخير ♥
@rabahalmuhtaseb3612
@rabahalmuhtaseb3612 5 жыл бұрын
Hello Venkat. Thank you very much for this video. I have a question if possible, the example you did works fine for images and other files like Visio (.vxd) for example. However, it's not working for text files. I couldn't find examples about this topic. However, it seems I need to read the text file line by line and save it. Just wanted to know your feedback on this issue. Thank you very much.
@opraju
@opraju 5 жыл бұрын
Hi Venkat I Am getting error like NullReferenceException: Object reference not set to an instance of an object. string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); were i went wrong please guide me
@hetalchavan9446
@hetalchavan9446 4 жыл бұрын
have you found any solution yet? Even I am getting the same error
@aznbuboa
@aznbuboa 4 жыл бұрын
I created a separate view for upload and I could not get image to bind to the model's property. In Home controller, the photo property of EmployeeCreateViewModel always null.
@Freeliner75
@Freeliner75 4 жыл бұрын
Had to dig into it. You should add to your form in Create.cshtml: enctype="multipart/form-data" to make it work now.
@aznbuboa
@aznbuboa 4 жыл бұрын
@@Freeliner75 Thank you!!
@MikeS-yg7bv
@MikeS-yg7bv 5 жыл бұрын
Simple Amazing . Thank you so much !!!
@NachoDev
@NachoDev 3 жыл бұрын
Now with Bootstrap 5 it´s not necesary to insert the script for the file name, it does by itself
@Fetretim
@Fetretim 2 жыл бұрын
++
@vaibhavtrikolikar4902
@vaibhavtrikolikar4902 4 ай бұрын
++
@SultanAlyami
@SultanAlyami 5 жыл бұрын
Top Professional Solutions 👍🏼
@VidyasagarMadasu
@VidyasagarMadasu 5 жыл бұрын
Dear Venkat, In client machine, how to open a pdf document in a new browser window/new tab with highlighting a given word for search. The pdf document is in server. Is it required to have pdf reader installed in server. Same thing in case of excel , does it required MS-Excel to be installed in server in order to open a excel in the client machine. Please help .
@ymtan
@ymtan 5 жыл бұрын
Dear Venkat, Regarding the following code, hostingEnvironment.WebRootPath provides us the absolute physical path of the wwwroot folder. I would like to ask how the physical path of the wwwroot folder looks like ??? string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 5 жыл бұрын
wwwroot folder in in the root project folder. To see the physical path of the folder, simply right click on the wwwroot folder and select "Open Folder in File Explorer" from the context menu. On my machine the following is the physical path of the wwwroot folder C:\Projects\EmployeeManagement\EmployeeManagement\wwwroot Hope this answers your question.
@ymtan
@ymtan 5 жыл бұрын
I would like to clarify with you regarding the following code. This code will return C:\Projects\EmployeeManagement\EmployeeManagement\wwwroot\images Path.Combine(hostingEnvironment.WebRootPath, "images"); Am I correct sir ???
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 5 жыл бұрын
Yes, that's correct.
@nazibulhaque94
@nazibulhaque94 5 жыл бұрын
Hi I m binding dynamic image on img tag helper like this (). However the browset view source renders the image path but image is not showing . what i m doing mistake please help me
@zkop1
@zkop1 5 жыл бұрын
can u open the page source and click on the link. i got error that file cant be access
@zkop1
@zkop1 5 жыл бұрын
var stream = new FileStream(filePath, FileMode.Create); model.Photo.CopyTo(stream); stream.Dispose(); // remove all resources add this to your code, if works, put like on me
@nazibulhaque94
@nazibulhaque94 5 жыл бұрын
@@zkop1 yes i got the file not found error when i bind dynamic image
@nazibulhaque94
@nazibulhaque94 5 жыл бұрын
@@zkop1 when i inspect ,its showing image path successfully bind like this but its not generating version like this
@padmanabanm6115
@padmanabanm6115 4 жыл бұрын
Will this work if you store the images in root folder upon hosting on IIS?
@allahnoorqudosi7472
@allahnoorqudosi7472 5 жыл бұрын
Hi, venkat thank you so much for this video it is so useful for me how to download an uploaded image
@SelmanErhanekici
@SelmanErhanekici 5 жыл бұрын
it was nice to watch your video keep doing @kudvenkat
@jekscustombuilds585
@jekscustombuilds585 3 жыл бұрын
Hi, is there a way to overwrite the file or image using this method? For example, I just want to replace the image to save space on the server? Thanks in advance
@sgm251070
@sgm251070 5 жыл бұрын
Hi Kudvenkat, great tutorial so far, thankyou for making it. Just letting you know, I had to change line 6 in Details.cshtml from var photoPath = "~/images/" + (Model.Employee.PhotoPath ?? "noimage.jpg"); } to var photoPath = "/images/" + (Model.Employee.PhotoPath ?? "noimage.jpg"); } // to allow the image to show in the details view.
@vityamv
@vityamv 5 жыл бұрын
thnx man
@javaguitarist
@javaguitarist 4 жыл бұрын
Genius. What made you think of that if you don't mind my asking, Steve? I assume there is different syntax because of the @model HomeDetailsViewModel in details.cshtml but don't understand why there would be. In Django that is not an issue: you can use either one.
@sgm251070
@sgm251070 4 жыл бұрын
Thanks @@javaguitarist, sorry, but I can't remember, I think I might have read it someone online when researching why it didn't work.
@АнатолийБорткевич-ю4к
@АнатолийБорткевич-ю4к 5 жыл бұрын
Instead of creating new class EmployeeCreateViewModel it's better to add to existing class Employee two properties: public string PhotoPath { get; set; } [NotMapped] public IFormFile Photo { get; set; } So with Photo property we work on View and we don't have this column in DB table Employee (by owing to the attribute NotMapped: you also must add namespace System.ComponentModel.DataAnnotations.Schema). By means of PhotoPath property we save file path in DB. What do you think?
@salehalbalushi9864
@salehalbalushi9864 4 жыл бұрын
Yes this is the best way, specially for large models. No need to repeat the whole model just for one or two fields. Great video Venkat, You are the best. Thanks Advance.
@OnlineKillah
@OnlineKillah 4 жыл бұрын
Some of my images are being saved in the wrong orientation. Please help someone, how do I keep the original orientation?
@andreit.2583
@andreit.2583 4 жыл бұрын
Hello, have you found any solution for this issue?
@shafinhaque2179
@shafinhaque2179 5 жыл бұрын
An unhandled exception occurred while processing the request. IOException: The filename, directory name, or volume label syntax is incorrect : EmployeeManagment.Controllers.HomeController.Create(EmployeeCreateViewModel model) in HomeController.cs model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); I am having a problem to upload file !!!! its showing error :model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
@krutelut
@krutelut 5 жыл бұрын
I get the same error :S
@isen1
@isen1 5 жыл бұрын
Hello and first: GREAT GREAT GREAT and Thanks. I started learning how to code this summer. Now Iam very haby doing all ur tutorials. The last days I got stuck right here at the end. Everything worked fine till I changed the browser. If I use Firefox, everthings works good. Just as I tryed to debugg with edge or IE the line with "uniqeFilePath" in the Create Actionmethod didnt work anymore. IO Exception . The generated path was now double in the string. BUT i found a solution! add ...GetFileName()... method like this: ..... uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.Photo.FileName); ..... Hope U ca recommend this changing. Greatings from Germany
@bntdgp
@bntdgp 4 жыл бұрын
Sir, can you please tell me why I am not getting WebRootPath in hostingEnvironment? I am using visual studio 2019.
@saiffaidi8292
@saiffaidi8292 4 жыл бұрын
use instead of
@georgehuman7253
@georgehuman7253 4 жыл бұрын
Which one is more efficient: To store files in DB as byte array or to store them as URL in 'wwwroot' folder?
@earllibay6814
@earllibay6814 4 жыл бұрын
im a bit confuse , sorry and i am open to anyone could tell why, the question is , why does venkat still include the properties NAME, dept, and remove the ID instead only Photo property in the Seperate class ? what's the purpose of being inlcude in that seperate class. ? ? ? thankyou.
@AdvikaSamantaray
@AdvikaSamantaray 4 жыл бұрын
Can you please answer why created new copy of employee? Can't we add file path to existing instance received.
@Sunill_Waugh
@Sunill_Waugh 5 жыл бұрын
Hi Venkat I am receiving error "Access to the path 'E:\backup\f\MyLabs\KudvenkatEmployees\EmployeeManagement\wwwroot\images' is denied", how do I resolve this? Thanks in advance
@harishds91
@harishds91 5 жыл бұрын
Even im stuck with same thing. Were you able to find a fix?
@Sunill_Waugh
@Sunill_Waugh 4 жыл бұрын
@@harishds91 No
@harishds91
@harishds91 4 жыл бұрын
@sunilwagh I fixed it. I was making the mistake of passing just the uploadsfolderpath variable .it should have file as well. Use path.combine to combine uploadsfolder and imagefile into a variable and pass that variable to filestream.i Hope it helps.
@Sunill_Waugh
@Sunill_Waugh 4 жыл бұрын
@@harishds91 let me try it out, thanks a lot
@AshProgHelp
@AshProgHelp 5 жыл бұрын
Thanks for this video. Is it possible to upload .pdf file using this way?
@darkogele
@darkogele 5 жыл бұрын
any kind of file dude
@davidhainovitz2838
@davidhainovitz2838 4 жыл бұрын
Great Tutorial. I was wondering why you did not choose the Async version for uploading photos Thanks David
@SaurabhKumar-om2gz
@SaurabhKumar-om2gz 3 жыл бұрын
I have one doubt .We are not passing the value for index view for photopath so it will always be null.
@codeRS95
@codeRS95 5 жыл бұрын
Hello sir, I want to make Email property required on some condition only, not always. How should I proceed to achieve this?
@YogeshKumar-hm1nq
@YogeshKumar-hm1nq 4 жыл бұрын
Very nice and helpful video, You are awesome!!
@artiomandronic5383
@artiomandronic5383 5 жыл бұрын
Great Success!!!! very nice you are the best keep doing what u doing barbosa will love my test
@shrawanchoubey9224
@shrawanchoubey9224 5 жыл бұрын
When I publish the code and upload to the servee then image folder not shown in the publish folder. Actually i m try to upload the image using core library in web api project.
@SultanAlyami
@SultanAlyami 5 жыл бұрын
enctype="multipart/form-data" ؟
@joseluispinzon5794
@joseluispinzon5794 4 жыл бұрын
This only works for the ASP.NET 2.2 version, right? Because it doesn't work for the 3.1 version I'm working on :(
@mainframehardtutorials8441
@mainframehardtutorials8441 4 жыл бұрын
Nope. Its working for all versions
@TamNguyen-nf8kr
@TamNguyen-nf8kr 4 жыл бұрын
Hello, can you suggest me a solution for editing the information I created ? I having a problem with this when I cannot create an IFormFile variable to pass to my Edit action. I hope someone will know this !
@anildebata4949
@anildebata4949 3 жыл бұрын
Thanks sir for your content!! Very helpful ❤
@sudiptoatutube
@sudiptoatutube 4 жыл бұрын
Dear Venkat, you have created a FileSteam object. Shouldn't we close this stream?
@adorebeauty6539
@adorebeauty6539 3 жыл бұрын
So MVC Core performs many tasks as jquery ajax along not only just binding
@shubhasismahata4726
@shubhasismahata4726 5 жыл бұрын
how you have create ddl in this form that you haven't shown it.. could you explain it
@karimmessaoud3191
@karimmessaoud3191 4 жыл бұрын
Great job! Thank you!
@mrmoinn
@mrmoinn 5 жыл бұрын
Why is my file selection region invisible? Everything seems to work but the actual bar is invisible for some reason
@bashirmanafikhi
@bashirmanafikhi 5 жыл бұрын
thank you.. why don't we store the picture in the database ??
@rolandsoftwareguy2515
@rolandsoftwareguy2515 5 жыл бұрын
Hi Bashir, it's normally a space consideration. It's better to store the actual images somewhere that is optimised for large files. Also, it would help when you start having different versions of the same file eg thumbnails. Hope that helps
@bashirmanafikhi
@bashirmanafikhi 5 жыл бұрын
@@rolandsoftwareguy2515 thanks Roland
@wibisonoindrawan5756
@wibisonoindrawan5756 4 жыл бұрын
How can we upload files to SQL Server ? or convert IFormFile to Base64 ?
@tetley3737
@tetley3737 3 жыл бұрын
Using .net 5, the file upload in the controller was creating an empty file (size 0), and of course the images did not display. To fix this issue, I changed the file stream / copy method to the following (which worked): string uniquePhotoFilename = null; if (model.Photo != null) { string uploadFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniquePhotoFilename = $"{Guid.NewGuid()}_{model.Photo.FileName}"; //string filePath = Path.Combine(uploadFolder, uniquePhotoFilename); //model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); using (var stream = new FileStream(Path.Combine(uploadFolder, uniquePhotoFilename), FileMode.Create)) { model.Photo.CopyTo(stream); } } Thank you kudvenkat for the very informative series! Edit: I watched a few more episodes, and a modification is made to the code that implements the using statement for the file stream in part 56.
@cheonnismail3693
@cheonnismail3693 5 жыл бұрын
Nedd to do some changes in Homecontroller.cs for file upload. need to change from uniqueFileName = Guid.NewGuid().ToString() + "_" +model.Photo.FileName; to uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.Photo.FileName); With this I dont hit any error. Thanks bro for a very helpful video.
@kavindurandika2140
@kavindurandika2140 4 жыл бұрын
Did you see the photo that uploaded by this?
@03ferozmohd
@03ferozmohd 4 жыл бұрын
Thanks bro, its working for me
@nabilbenali2044
@nabilbenali2044 4 жыл бұрын
Thank you bro it worked
@naodagere8210
@naodagere8210 4 жыл бұрын
Sure worked this for me
@jamilamini7807
@jamilamini7807 5 жыл бұрын
where Can i find source code for the playlist ?
@jnaz000
@jnaz000 3 жыл бұрын
Is it possible to upload via Blob Storage on Azure?
@shahidwani6445
@shahidwani6445 5 жыл бұрын
Thank you, please also make video on dataprotection provider in core
@factgasm2365
@factgasm2365 5 жыл бұрын
Try this. docs.microsoft.com/en-us/aspnet/core/security/data-protection/using-data-protection?view=aspnetcore-2.2
@rbhati23
@rbhati23 4 жыл бұрын
Thanks fir the Great Video. had to tweak a little things to get the images loaded in correct path.Initially the images wasloaded, ond ebussing found that Images was not getting copied to images folder. duirng creating path : it coming like "wwwrootimages" when ideally it should come as "wwwroot\images" So just added "\\" to path between webroot and images, and also between images and uniquefilename.
@shirajkesaribaidya801
@shirajkesaribaidya801 3 жыл бұрын
my images are in different size even if i am using the css class like you did can someone help, please?
@waqasriaz30
@waqasriaz30 4 жыл бұрын
My images are not styling properly. Height varies and not set to 200px
@hetalchavan9446
@hetalchavan9446 4 жыл бұрын
same issue with me
@BigAlNavidi
@BigAlNavidi 3 жыл бұрын
Is there any place we can actually download the solution for this?
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 3 жыл бұрын
Hello AI - Yes, you have all the instructions on the following article. Hope this helps. csharp-video-tutorials.blogspot.com/2019/11/aspnet-core-mvc-course-wrap-up.html
@coolwaterdvr
@coolwaterdvr 5 жыл бұрын
Thank you Venkat.
@TyGuy96
@TyGuy96 4 жыл бұрын
The program will crash after uploading a file using the Brave web browser. I had to switch to Chrome to make it work.
@gundulf5686
@gundulf5686 4 жыл бұрын
THANK YOU FOR THIS COMMENT!
@rkvijayvargiya6682
@rkvijayvargiya6682 4 жыл бұрын
I wasalso using the brave browser. I switched to Mozilla and everything worked fine. Do you know why?
@МарсельХамидуллин-ь6е
@МарсельХамидуллин-ь6е 4 жыл бұрын
How should I apply css? Doesnot work
@vinays1234
@vinays1234 4 жыл бұрын
Please make a video on uploading image to database, and displaying it on web page.
@SyriaNabek7445
@SyriaNabek7445 2 жыл бұрын
Just perfect
@СтефанИвковић
@СтефанИвковић 5 жыл бұрын
model.Photo is always null , why?
@waqasriaz30
@waqasriaz30 4 жыл бұрын
You must have forgot to add enctype="multipart/form-data" in form tag under create.cshtml view.
@shaiktaher6163
@shaiktaher6163 5 жыл бұрын
Photo value is null on postback, (model.Photo!=null) is always false
@catarinaribeiro8088
@catarinaribeiro8088 4 жыл бұрын
where the Dept came from ?
@chakotay9996
@chakotay9996 5 жыл бұрын
Tank you sir!
@NiazMohammad
@NiazMohammad 4 жыл бұрын
the dbo.Employees table doesn't show the photoPath. Anyone else having such issues?
@oibwankenobi
@oibwankenobi 5 жыл бұрын
Can you do the same vidéo, but with a database plz? i'm trying to save a file into database for cloud gaming save
@politicaltelegraph6339
@politicaltelegraph6339 5 жыл бұрын
Thank you sir..
@acggermed7271
@acggermed7271 4 жыл бұрын
hello friend, why not provide the sources for this video lesson?
@jcchin5497
@jcchin5497 5 жыл бұрын
how about download ?
@codeautomate8155
@codeautomate8155 5 жыл бұрын
what is navigation property
@AshutoshKumar-kt1dd
@AshutoshKumar-kt1dd 5 жыл бұрын
Great
@TheAbubakarbaig
@TheAbubakarbaig 4 жыл бұрын
why didn't you created a partial class of employee instead of making a whole new class with photo prop?
@TheAbubakarbaig
@TheAbubakarbaig 4 жыл бұрын
ok my bad, its creating field for it in the database even its in the partial class.
@lordjim9971
@lordjim9971 4 жыл бұрын
Great but how to download file?
@j0natan87
@j0natan87 4 жыл бұрын
Couldnt get the label to replace "Choose file..." with the filename with this solution so I did this instead and it works: document.querySelector('.custom-file-input').addEventListener('change', function (e) { var fileName = document.getElementById("Photo").files[0].name; var nextSibling = e.target.nextElementSibling nextSibling.innerText = fileName })
@HDoBEAST
@HDoBEAST 4 жыл бұрын
Where did you put that?
@codeautomate8155
@codeautomate8155 5 жыл бұрын
thank you
@suhagpatel4146
@suhagpatel4146 5 жыл бұрын
Hi Sir, Please Upload xamarin Videos Advanced Thank you.
@Asisvenia
@Asisvenia 5 жыл бұрын
If you get null IFormFile then try to use: HttpContext.Request.Form.Files[0] it will fix your problem. I spent many hours to fix this issue. So, create a variable like this: var getImgFile = HttpContext.Request.Form.Files[0]; and instead of using model.Photo use getImgFile. My whole code: [HttpPost] public IActionResult Create(Gpu gpuData) { if (ModelState.IsValid) { var getImgFile = HttpContext.Request.Form.Files[0]; int maxId = GpuMockData.GpuCollection.Max(g => g.Id); gpuData.Id = maxId + 1; ///Check if image is null or not string uniqueImageName = null; if(getImgFile != null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniqueImageName = Guid.NewGuid().ToString() + "_" + getImgFile.FileName; string filePath = Path.Combine(uploadsFolder, uniqueImageName); getImgFile.CopyTo(new FileStream(filePath, FileMode.Create)); } gpuData.Image = uniqueImageName; GpuMockData.GpuCollection.Add(gpuData); return RedirectToAction("Index", "Home"); } return View(); }
@favorivideo628
@favorivideo628 4 жыл бұрын
nope that did not help, same issue
@Olegcowboyoleg
@Olegcowboyoleg Жыл бұрын
Зачем мы делаем ЭТО var photoPath = "~/images/" + (Model.Employee.PhotoPath ?? "noimage.jpg"); вместо того чтобы использовать ЭТО string filePath = Path.Combine(uploadsFolder, uniqueFileName); (из класса HomeController) ???????????????????????????? Why do we do that var photoPath = "~/images/" + (Model.Employee.PhotoPath ?? "noimage.jpg"); instead string filePath = Path.Combine(uploadsFolder, uniqueFileName); (from HomeController class)
@Olegcowboyoleg
@Olegcowboyoleg Жыл бұрын
But you are still the BEST teacher!!! I'll see you Bootsrap course, and CSS.
@hetalchavan9446
@hetalchavan9446 4 жыл бұрын
In my case, all the 3 employees are not in one row. Only 2 of them are there per row.
@arnoldjohn8620
@arnoldjohn8620 4 жыл бұрын
If anyone using .core 3.1 then u probably see a green squidly in Ihostingenvironment Then use IWebHostEnvironment
@ajwagroindustry7454
@ajwagroindustry7454 3 жыл бұрын
Sr Please Update Your Coursee
@ivanb8662
@ivanb8662 4 жыл бұрын
Now need to use IWebHostEnvironment instead IHostingEnvironment
@papypypa485
@papypypa485 5 жыл бұрын
I think im in love with Sara ...
@amitlimbu5025
@amitlimbu5025 5 жыл бұрын
Now use IWebHostEnvironmen
@mainframehardtutorials8441
@mainframehardtutorials8441 4 жыл бұрын
Yes because IHosting Environment should be removed so its better to use IWebHostEnvironment
@amitkumar-fi2tb
@amitkumar-fi2tb 4 жыл бұрын
Now i am feeling bore because your tutorial no longer effective...
@NiazMohammad
@NiazMohammad 4 жыл бұрын
Because you are lazy to search for the updated code and learn.
Upload multiple files in asp net core mvc
10:51
kudvenkat
Рет қаралды 87 М.
Routing in ASP NET Core MVC
12:01
kudvenkat
Рет қаралды 191 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Add or remove users from role in asp net core
24:30
kudvenkat
Рет қаралды 85 М.
Global exception handling in asp net core mvc
9:08
kudvenkat
Рет қаралды 110 М.
Extend IdentityUser in ASP NET Core
10:52
kudvenkat
Рет қаралды 103 М.
Implementing login functionality in asp net core
14:11
kudvenkat
Рет қаралды 172 М.
ASP NET Core google authentication   setting up the UI
14:16
kudvenkat
Рет қаралды 65 М.
Creating roles in asp net core
12:20
kudvenkat
Рет қаралды 134 М.
Attribute Routing in ASP NET Core MVC
14:14
kudvenkat
Рет қаралды 147 М.
Repository pattern in asp net core
14:50
kudvenkat
Рет қаралды 308 М.
Edit role in asp net core
18:27
kudvenkat
Рет қаралды 69 М.
Forgot to add few columns to Entity Framework migration
6:29
Kareem Sulthan
Рет қаралды 5 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН