Answer the question
In order to leave comments, you need to log in
How to view files in a category and open them in the C# program itself?
The point is this. Going to a specific tab in the tabControl, the user immediately sees two windows. On the left, files from a specific folder of the .pdf extension are displayed (it would be great if there were other extensions). By choosing any name, a file opens on the left, where the user can simply watch it without changes. Tell me, please, how can this be done?
Answer the question
In order to leave comments, you need to log in
So far only for pdf-files. For Word files, I came up with an option only with converting the file to pdf and displaying the pdf file on the screen.
private void button1_Click(object sender, EventArgs e)
{
// перейти во вторую вкладку
tabControl1.SelectTab(1);
// очистить отображаемый список файлов
listView1.Items.Clear();
// отобразить список pdf-файлов из директории
foreach (string file in Directory.GetFiles(@"H:\Test\333", "*.pdf"))
{
listView1.Items.Add(new ListViewItem() { Text = Path.GetFileName(file), Tag = file });
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
// потому что при смене выбранного значения этот обработчик ловит ситуацию когда число выделенных элементов равно нулю, данный "костыль" нужен как раз для таких случаев
if (listView1.SelectedIndices.Count <= 0)
return;
// вывести содержимое файла на экран
webBrowser1.Navigate(listView1.SelectedItems[0].Tag.ToString());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question