简体   繁体   中英

Folder upload in asp.net web forms

I need to upload a folder without zipping it.
Folder may also contain sub-folders and files.
Is it possible?

User has to select the files. You can't from code out of the blue select a singe file, or multiple files from code.

The reason is for security. If I could write code that selects a file without user interaction, then while you visit my site to say view a cat video, I will steal all your files - I will grab your email lists, and even look for say a excel file called passwords. And I'll look for and grab and steal files called banking information. As a result, NO browser allows you or your code to select a single file, or even multiple files. Too big of a security hold and thus not allowed.

So your browser client side code can NOT select a file. The USER must select that file.

You can have the user browse to a folder, open it, and then say hit ctrl-A if the file upload control supports multiple file selections. But in ALL cases, the USER must select each file. You can't select a folder, nor can you with client code select a folder.

If this was possbile, then this would be a massive secuirty hole, since then any one visting any site could have the browser simply go and select any old file without the users knowledge or even controling or wanting to allow, or not allow files to be up-loaded.

So, this is a browser lockdown issue. If someone came out with a browser that allowed this, then no one would use that browser since it would be too high of a secuirty risk.

So client side code can't even set, or change select a simple single file - the USER must do this action. As a result, it not possible to select even a folder to up-load - the user must do this.

So you can adopt one of many file up-load controls that allows the user to make multiple selections - but that multiple selection of a single file, or many files MUST occur by user actions selecting files - client side code can NEVER select, pick or choose a file name for security reason. Only USER actions can select a file - never client side code - it simply not allowed, and it simply never going to be allowed for reasons of security.

So a file control that allows multiple file selections - to allow the user to select all the files in a folder quickly? yes, but no folder selecting is allowed. The user will have to browse to the folder - select files to upload. They could then open/add another folder and select files from that folder. But no folder, or even a simple single file can be obtained, picked or touched or used by client side code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM