2

Is there any way I can get a file explorer to open up and allow the user to choose a folder destination in a website ? I want to then save this location and this will be the location for uploads.

Chris
  • 175
  • 1
  • 3
  • 17
  • 1
    OpenDialog or a SaveDialog it's very simple to use – MethodMan Aug 29 '14 at 17:37
  • On the server or on the client machine? – Zuzlx Aug 29 '14 at 17:39
  • 1
    It works well for either if the OP were to use the `` just needs to make sure that the website where users will be running the webpage, that machine has read/write access to the drop off folder location.. I am using this currently flawlessly.. and even works with asych fileuplods too – MethodMan Aug 29 '14 at 17:40
  • 1
    there is a good reference here [FileUpLoad Class MSDN](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload(v=vs.110).aspx) – MethodMan Aug 29 '14 at 17:42
  • i want the user on the client side to do this – Chris Aug 29 '14 at 17:46
  • What will you upload to the client machine? – CodeCaster Aug 29 '14 at 17:52
  • Let me understand. You want a user, sitting at its client machine, open a window that shows the server side folders and then choose one for its uploads? – Steve Aug 29 '14 at 17:56
  • no. I want the user to browse their folders and choose a folder location. forget about uploading anything. I just want them to be able to select the location. eg D:\\library\\this_is_where_i_want_to_upload – Chris Aug 29 '14 at 17:59
  • 1
    Then you have your answer in @DJKRAZE comments – Steve Aug 29 '14 at 18:00
  • 1
    Chris I do not think that you understand web interface / client side coding as well as how FileUpload control works.. it's straight forward and requires very little coding also within the filupload control you should look up how to use the following method `this.FileUpload.HasFile` and `this.FileUpload.SaveAs()` of course fileupload in my case is named FileUpload1 – MethodMan Aug 29 '14 at 18:04
  • 1
    This is not possible inside a web browser without a plugin like Java or ActiveX. The file dialog in a browser won't select a folder, and for security reasons modern browsers often won't even reveal the full local path of a file that has been selected; only the file name. – Rex M Aug 29 '14 at 18:19
  • I have a file upload routine that looks at a folder location and uploads all the files in that folder. I just want the user the select a folder directory for where to look i then save this location to the database. – Chris Aug 29 '14 at 19:11

2 Answers2

-1

Use the following code. Its working for me.

protected void browse_Click(object sender, EventArgs e) {

        Thread thdSyncRead = new Thread(new ThreadStart(openfolder));
        thdSyncRead.SetApartmentState(ApartmentState.STA);
        thdSyncRead.Start();

    }
    public void openfolder()
    {

        FolderBrowserDialog fbd = new FolderBrowserDialog();
        DialogResult result = fbd.ShowDialog();

        string selectedfolder = fbd.SelectedPath;


        string[] files = Directory.GetFiles(fbd.SelectedPath);
        System.Windows.Forms.MessageBox.Show("Files found: " + files.Length.ToString(), "Message");

    }
John Saunders
  • 160,644
  • 26
  • 247
  • 397
VishwajeetMCA
  • 139
  • 2
  • 12
  • 1
    That code works for you in ASP.NET? It is Windows Forms code. – John Saunders Jan 13 '15 at 06:37
  • Above code can also be used in ASP.NET code. We just need to add two references in the program. using System.Threading; & using System.Windows.Forms; – VishwajeetMCA Jan 13 '15 at 07:50
  • 1
    @John Saunders: You could have check before asking VishwajeetMCA. I could see the dialog, but opening behind the active window. Hence, I have flagged your comment. – Ashok kumar Feb 17 '16 at 11:36
  • 2
    @ashok sorry, it does NOT work. You clearly do not understand Web vs. Desktop. That window appears on the server. The only reason you see it is that you are debugging. Today, because you are debugging, the client and server are the same machine. In the general case there will be many clients and only one server. The window will _still_ only appear on the server, and the client's will never see it. – John Saunders Feb 17 '16 at 11:57
  • @John Saunders: Thank you very much for clear explanation. Sorry for my mistake. As it is bit late, I am unable to withdraw the up-vote given to VishwajeetMCA's answer. Thank you once again for your valuable input. – Ashok kumar Feb 17 '16 at 12:58
-1

I recommended Roxy Fileman, it's free and simple to use in my experiences.

Hope you enjoy it :)

zey
  • 5,939
  • 14
  • 56
  • 110