4

I have an import form on my asp.net page. There are 2 browse controls. The first allows the user to select a file (typical). For the second one I want the user to be able to select a folder/dir (because I want to import all files in that directory.) How can I do this? Currently I'm using this but it only works with files. I want the user to only be able to select a folder....

 <asp:FileUpload ID="DirUpload" runat="server" />
WebDevGuy2
  • 1,159
  • 1
  • 19
  • 40

2 Answers2

1

Cannot be done using conventional means. Might be possible using a third party component or hacks.

See this question: Directory Chooser in HTML page

Community
  • 1
  • 1
mxmissile
  • 11,464
  • 3
  • 53
  • 79
0

Actually you can do like this: (i am posting answer with mobile so excuse me for misspelling)

aspx code 

<asp:FileUpload ID="fuImages" runat="server" AllowMultiple="true" /> <asp:Button ID="btnUploadImages" Text="Upload Images" runat="server" OnClick ="UploadMultipleImages" accept ="image/gif, image/jpeg" /> <br /> <asp:Label ID="lblResult" runat="server" /> 

Code Behind:

protected void UploadMultipleImages(object sender, EventArgs e) 
{ foreach (HttpPostedFile postedFile in fuImages.PostedFiles)
 { string fileName = Path.GetFileName(postedFile.FileName); postedFile.SaveAs(Server.MapPath("~/Gallery/") + fileName); }
 lblResult.Text = string.Format("{0} files have been uploaded successfully.", fuImages.PostedFiles.Count); }
A Programmer
  • 625
  • 8
  • 30
  • The `AllowMultiple` attribute lets you select multiple files, does not allow you to select a "folder" entity. – mxmissile Oct 13 '15 at 00:34
  • Yeah, so u can select all items in a folder instead of selecting a folder, i think it's same as @WebDevGuy2 wants. – A Programmer Oct 16 '15 at 14:33