Click here to Skip to main content
15,907,679 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
protected void btnbrowseInventory(object sender, EventArgs e)
{
    Thread thdSyncRead = new Thread(new ThreadStart(openfolder));
    thdSyncRead.SetApartmentState(ApartmentState.STA);
    thdSyncRead.Start();
    thdSyncRead.Join();
    
    txtfilepath.Text = selectedfolder;
    lblMessage.Visible = false;
}

public void openfolder()
{
    FolderBrowserDialog fbd = new FolderBrowserDialog();
    DialogResult result = fbd.ShowDialog();
   
    selectedfolder = fbd.SelectedPath;
}
Posted
Updated 20-May-15 2:11am
v2
Comments
Abhipal Singh 20-May-15 8:09am    
FolderBrowseDialog is a WinForms control. Are you opening the dialog box on server side?
Richard Deeming 20-May-15 8:39am    
Sounds like the answer to me!

When you're debugging in Visual Studio, it almost appears to work, but only because the client and the server are the same computer in that specific case.

That seems to cause a lot of confusion for developers who are new to ASP.NET.
ZurdoDev 20-May-15 8:35am    
What? This does not make any sense.
Member 11527624 20-May-15 8:40am    
I have added the system.windows.forms assembly in my solution as a reference and so it is workinng fine.But the problem is when i click on browse it displaying the window at the back of application
Sinisa Hajnal 20-May-15 8:49am    
It will NOT work once you deploy it on the web server. Any dialog from win forms will open on the computer running the application (i.e. web server) and WILL NOT show on the client computer. All you'll get is blocked web application (since there will be no one to close the dialog on the server)

It will work on your machine because you are web server for development. But try to publish your app on some other machine and it will block.

1 solution

The thing is, if you deploy the application on a web server and try to access it on client, It will not work and your page will hang waiting for an input.

Currently, your client and server both are on the same machine and hence you can see the dialog box(but that dialog is actully opening on server side).

You need to have a custom control which will open on client side. Check the link below: Directory Browsing in ASP.Net 2.0[^]
 
Share this answer
 
Comments
Member 11527624 20-May-15 9:04am    
Could you provide me with some code.i have checked the above link but if we gonna use that in the master page then it is opening repetitive windows and not working properly
Abhipal Singh 20-May-15 9:17am    
What are you trying to achieve by browsing the folder paths?

Are you are trying to upload files from client machine?

If yes, then use FileUpload asp control. Its straight forward. You just have to drag and drop it on your page.
Member 11527624 20-May-15 9:24am    
NO i am saving the folder path in one table and files in the folder path into another folder what user has selected into another table and displaying it according to the selection of the user from UI.
Sergey Alexandrovich Kryukov 20-May-15 9:35am    
5ed. Too bad the inquirer is not getting it...
—SA
Abhipal Singh 20-May-15 9:54am    
@SA: Thanks for upvoting :)
@Member 11527624: I am afraid there is nothing ready made for folder browsing in ASP. However, there are a lot of open source code available on internet all you need to do is search one and make it fit in your application. People have made custom controls for this purpose.
The best example I can quote is of Telerik(its paid though).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900