Problem with Open Dialog box
-
Hi Folks, i have a problem with common dialog', I need to open a file when i click the item from listbox. now i got open dialog with specified path but it dont open the file. can you plz give idea to solve this. my code is here., the following code in selected index changed event for thet listbox. OpenDialog.FileName="Filepath"; OpenDialog.OpenFile(); OpenDialog.ShowDialog(); ranandbe
-
Hi Folks, i have a problem with common dialog', I need to open a file when i click the item from listbox. now i got open dialog with specified path but it dont open the file. can you plz give idea to solve this. my code is here., the following code in selected index changed event for thet listbox. OpenDialog.FileName="Filepath"; OpenDialog.OpenFile(); OpenDialog.ShowDialog(); ranandbe
??? I don't understand your code and what do you want to do with that, but normally I use it like this:
OpenFileDialog openFileDialog = new OpenFileDialog();
DialogResult dialogResult = openFileDialog.ShowDialog();
if(dialogResult == DialogResult.OK && openFileDialog.FileName != "")
{
// use something with this filename (openFileDialog.FileName)
// For example :
// FileStream fileStream = new FileStream(openFileDialog.FileName, FileMode.Open);
// ...
// fileStream.Close();
}or
OpenFileDialog openFileDialog = new OpenFileDialog();
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.FileStream filestream = openFileDialog.OpenFile();
// ... use something with filestream
filestream.Close();
}Before ShowDialog() you can only set the property like Path, Filter, etc... Then you must call ShowDialog() to show the dialog. If the user select a file and click OK, then you get a return value DialogResult.OK. Then you can get the filename by calling openFileDialog.FileName.