Skip to content
Advertisement

Is there any way to get full path of file in form?

I am trying to get file by input element of type “file”. That element is in partial view and I want to send it to controller or request it there by “Request.Form[“inputFile”];”. This way give me only name of the file. In the controller i want to send it via email attachment but I need to load that file.

Aplication is ASP.NETCore Razor Pages and elements like Request.Files[] are not there.

Does anyone has some idea to achieve this?

Advertisement

Answer

This way give me only name of the file. In the controller i want to send it via email attachment but I need to load that file.

It seems that you’d like to enable browser user to upload file(s) through form’s file input field. Please note that the file location on the client’s machine is not accessible from web server, if you want to send user selected file as email attachment, you can save the uploaded file on your web server or other storage service etc first, then access the stored file and send it via email attachment in your code logic.

And this doc is about “Upload files in ASP.NET Core”, you can refer to it.

https://learn.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-5.0

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement