TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mohamed Moumni
NA
48
8.4k
how to open a file selected in listbox ?
Jun 3 2017 7:22 PM
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);
}
Reply
Answers (
1
)
Alert when date matches with system date(C# windows form app
How can I change Date/Time format in database?