Hi,

Please suggest me to do FolderBrowserDialog box for "C# Web Application".

Thanks a lot,
Anjali

Dani AI

Generated

Short version: a Windows Forms folder picker runs on the server process and depends on an interactive desktop and a COM/STA UI thread. That makes it unsuitable for an ASP.NET page: it will either fail under the debugger, show an empty dialog, or (worse) pop up on the server instead of the client. tried the Forms picker and was right to point out the mismatch.

Two correct approaches depending on intent:

  • If users must pick a folder on their own machine and upload its contents, use a client-side file input that allows directory selection (browser support varies) and then upload the files. Example HTML (Chrome/Edge support via a vendor attribute):
<input type="file" id="files" webkitdirectory directory multiple>

On the server iterate uploaded files (Request.Files / FileUpload control) and save/process them. See the HTML file input reference for browser details: input type=file (MDN).

  • If the goal is to choose a folder on the web server, build a server-side directory browser (use Directory.GetDirectories, return a JSON tree or render a TreeView). That avoids any client/server UI mismatch and works under the app pool identity and IIS permissions.

If you must run a desktop picker on client machines, use a small client helper (ClickOnce or a signed WinForms app) to collect the path and post it back to the server; see ClickOnce deployment for options: ClickOnce overview.

Troubleshooting notes: to reproduce behavior safely, test the folder picker in a local WinForms app (not in ASP.NET). If experimenting on the server, remember non-interactive service accounts, session-0 isolation and missing user profiles will cause empty views or permission problems; changing process identities to get an interactive desktop is not a recommended production fix. For the FolderBrowserDialog class details see Microsoft docs: FolderBrowserDialog.

Recommended Answers

All 5 Replies

why you need to develop it yourself as it exists? just add reference to System.Windows.Forms and use it in your web-based application.

Ya that's the great idea.
But iam getting this execption , can you please suggest me for this.

Exception : "Current thread must be set to single thread apartment(STA) before OLE calls can be made. Ensure that your main function has STAThreadAttribute marked on it . This exception is only raised if adebugger is attached to the process."

Thanks a lot,
Anjali

Just because you debug, run your web-based application (Ctrl + F5) there is no exception.

Its not working properly with (ctr + f5) also. Its very slow and FolderDialog is opening but does not contains anything..

Please check out the bellow code n please suggest me for the same.

private void btnBrowse_Click(object sender, EventArgs e)
{
    FolderBrowserDialog RootFile = new FolderBrowserDialog();
    if(RootFile.ShowDialog() == DialogResult.OK)
    {
        txtRootFolder.Text = RootFile.SelectedPath.ToString();
     }
} 

Thanks a lot,
Anjali ...

Authentication problem, I'll reply you ASAP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.