Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help,I am using
IFormFile File
to upload file in MVC C#. Now in Edit mode can i show that file so that user need not to select again on Submit? Otherwise it become empty model in Edit Mode. Also i am storing data in binary format in DB.

What I have tried:

So far I have tried creating
IFormFile File
object return from Controller but while returning in json format it through error.
Posted
Updated 29-Sep-22 21:45pm

1 solution

No. You cannot pre-populate an <input type="file">, since that would allow random websites to trick users into uploading files from their computer without knowing which file they were uploading.

And even if you could, your site never receives the full path of the file on the user's computer; just the file name and the contents of the file. That wouldn't be enough information to select the same file again.

And even if that wasn't the case, there's no guarantee that the file would still exist in the same path, and wouldn't have changed since it was first uploaded. And there's no guarantee that the edit happens on the same computer that the file was first uploaded from.

The best you can do is to display some sort of indicator that a file already exists, and ignore the file in the POST action if it's null or empty.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900