public partial class Form1 : Form
{
private String[] selectedFiles;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Open a file to process";
openFileDialog1.Multiselect = true;
//selectable file types
openFileDialog1.Filter = "Portable Document Format (*.pdf)|*.pdf|Text Documents(*.txt)|*.txt|Executable(*.exe)|*.exe|MPEG Layer 3 File(*.mp3)|*.mp3";
openFileDialog1.InitialDirectory = "c:";
DialogResult respo= openFileDialog1.ShowDialog();
if (respo == DialogResult.OK)
{
selectedFiles = openFileDialog1.FileNames;
}
else
{
textBox1.Text = "No selected file!";
}
}
private void button2_Click(object sender, EventArgs e)
{
dataGridView1.Columns.Add("FileName", "File Name");
dataGridView1.Columns.Add("FileSize", "File Size");
dataGridView1.Columns.Add("IsSystem", "Last Accessed Time");
//dataGridView1.Rows.Add(new Object[] { "A.php", "2345KB", "True" });
//dataGridView1.Rows.Add(new Object[] { "CV.doc", "3543KB", "False" });
//dataGridView1.Rows.Add(new Object[] { "cmd.exe", "35763KB", "True" });
foreach (String file in selectedFiles)
{
FileInfo fObj = new FileInfo(file);
String fileName;
try
{
fileName = file.Substring(file.LastIndexOf('\\') + 1);
}catch(ArgumentOutOfRangeException ex)
{
fileName = file;
}
long leng = fObj.Length;
bool isReadOnly = fObj.IsReadOnly;
DateTime lwt = fObj.LastWriteTime;
String lastAccess = lwt.ToString();
dataGridView1.Rows.Add(new Object[]{fileName,leng,lastAccess});
Console.WriteLine(fileName);
}
}
Friday, February 3, 2012
Using DataGridView to Show Data in a table
Selecting multiple files and show their information on a DataGridView
Labels:
C#.net,
Data,
DataGridView,
table
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment