Список доступных для открытия файлов из заданной папки - C#
Формулировка задачи:
Как создать приложение, при открытии которого в comboBox добавляется список доступных файлов для открытия (например txt) в заданной раннее папке?
Решение задачи: «Список доступных для открытия файлов из заданной папки»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.DisplayMember = "Name";
comboBox1.DataSource = new System.IO.DirectoryInfo(@"E:\").GetFiles("*.txt");
}
private void button1_Click(object sender, EventArgs e)
{
var file = comboBox1.SelectedItem as System.IO.FileInfo;
if (file != null)
System.IO.File.OpenRead(file.FullName);
}
}
}