Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
how to open a file selected in listbox ?
Mohamed Moumni
Jun 3 2017 7:22 PM
252
Reply
I have all the dirctories (2014, 2012), the files of each selected folder (.pdf) in the listbox 2
get the dirctories by this code ,
if
(FBD.ShowDialog() == DialogResult.OK)
{
listBox1.Items.Clear();
DirectoryInfo[] diri_info =newDirectoryInfo(FBD.SelectedPath).GetDirectories();
foreach
(DirectoryInfo diri
in
diri_info)
{
listBox1.Items.Add(diri);
}
and i get the files by this code
private
void
button1_Click(
object
sender, EventArgs e)
{
if
(listBox1.SelectedIndex >= 0)
{
DirectoryInfo dirictory_choisis = (DirectoryInfo)listBox1.SelectedItem;
FileInfo[] files = dirictory_choisis.GetFiles();
listBox2.Items.Clear();
foreach
(FileInfo file
in
files)
{
listBox2.Items.Add(file);
}
}
else
{
MessageBox.Show(
"selectioner un dossier"
);
}
}
Now how I can open the selected file (.pdf) ?
i use this code but dosn't work ( throw an exception file dosn't found)
private
void
listBox2_Click(
object
sender, EventArgs e)
{
FileInfo file =(FileInfo) listBox2.SelectedItem;
Process.Start(file.Name);
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Alert when date matches with system date(C# windows form app
How can I change Date/Time format in database?