0

I have a question. I need to get a folder from user on the page and save hierarchy of folders' names to db. If I use IFormFile it takes only files, but I need exactly folders even if they are empty. How can I implement this?

This is form:

<form action="/Folders/Upload" method="post" 
enctype="multipart/form-data">
    <input type="file" directory multiple>
    <input type="submit" value="Upload">
</form>

In controller I tried to get List<IFormFile> but it takes only files if they exist in folders and if there aren't any files it's Length is 0. But I need to get hierachy of folders(their names) even if there aren't any files. Can I somehow save the whole hierachy of folders or maybe take a zip from user?

Bubbler
  • 1
  • 2
  • Following has example code to recursively go through a directory to get files and folders : https://learn.microsoft.com/en-us/dotnet/api/system.io.directoryinfo?view=net-7.0 – jdweng Mar 04 '23 at 09:49
  • @jdweng I know, but to create `DirectoryInfo` instance I need a path, so to do this I need to save folder from user's input – Bubbler Mar 04 '23 at 09:55
  • 1
    The root folder is a string. So have user either type a string or use Folder Browser : https://stackoverflow.com/questions/25573385/folder-browser-asp-net-website – jdweng Mar 04 '23 at 10:12
  • Do you need to get the folder path of the user's machine? – Chetan Mar 04 '23 at 10:43
  • you want to get folder directory, then pls ask user to enter folder directory. https://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav – Tiny Wang Mar 06 '23 at 09:59

0 Answers0