Click here to Skip to main content
15,889,552 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to open a folder dialog on a button click and need that path in a variable so that i can use it to extract all the images in the selected folder.
I am using MVC 4 with razor view . please rply for cshtml page.
I know how to open a file dialog but need a folder dialog.

What I have tried:

This is for file dialog but need to select a folder instead

<div>
Select Image <input type="file" name="file" />
<input type="submit" value="Upload Images" name="Command" />
<br /><br />
Filename = @ViewBag.filename
<br />
ImageUrl = @ViewBag.ImageURL
</div>
Posted
Updated 10-Aug-17 3:18am

1 solution

If you want to upload an entire folder, then you need to add the multiple and directory attributes to the file input:
C#
<input type="file" name="file" accept="image/*" multiple directory webkitdirectory mozdirectory />

NB: You currently need to include the vendor-prefixed versions of the "directory" attribute as well.
HTMLInputElement.webkitdirectory - Web APIs | MDN[^]

This is an unofficial extension to the HTML standard. It works in Edge, Firefox, Chrome, and Opera. It doesn't work in any version of IE or Safari, or in mobile browsers.
Can I use... Directory selection from file input[^]

In browsers that don't support it, the multiple attribute will ensure that users can still select multiple files to upload.

In either case, the Request.Files collection will contain an HttpPostedFile for each posted file.
 
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