Reputation: 147
I have created a simple asp.net web application. It has two buttons one for browsing folder (selectFolderbtn) & another for browsing file (selectFilebtn) . And the click event for both the buttons are as below:-
protected void selectFolderbtn_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;
txt_extDestLoc.Text = selectedfolder;
}
protected void selectFilebtn_Click(object sender, EventArgs e)
{
Thread thdSyncReadNew = new Thread(new ThreadStart(selectfile));
thdSyncReadNew.SetApartmentState(ApartmentState.STA);
thdSyncReadNew.Start();
}
public void selectfile()
{
OpenFileDialog fileD = new OpenFileDialog(); //create object
fileD.Filter = "Iso files|*.iso;"; //define filter
fileD.ShowDialog(); //show dialog
string globalisopath = fileD.FileName;
}
The issue I am facing is, among the above two button click event only one event works at a time & not both the event. I want both the click event to work, one should select a folder & another should select a file. But its not working the way I want.
Why this is happening. Please suggest me its solution or any other alternatives.
Upvotes: 1
Views: 349
Reputation: 63742
You're solving the wrong issue.
There is no legitimate reason to use any windows dialog in a web application. It will only ever show the dialog on the server (and most likely, not even that). You need to handle this on your own - either you want the user to upload some files, and there's controls for that, or you want him to select a file / folder already existing on the server - and that's completely different.
You cannot use any windows controls in a web application at all. You need to use web controls, or write your own HTML+JavaScript etc.
Upvotes: 1