I am creating a dynamic table for listing files.
It shows filename, filesize, dateModified columns. In addition, I have added one more columns: Delete.
The method which lists files of a folder in a table.
public void listFile()
{
var dir = new DirectoryInfo(selectedFolder);
Table fileTable = new Table();
foreach (var file in dir.GetFiles())
{
TableRow tr = new TableRow();
TableCell td1 = new TableCell();
TableCell td2 = new TableCell();
TableCell td3 = new TableCell();
TableCell td4 = new TableCell();
Label name = new Label();
Label size = new Label();
Label dateMod = new Label();
LinkButton btn_delete = new LinkButton();
name.Text = file.Name;
size.Text = (file.Length / 1024) + " KB";
dateMod.Text = file.LastWriteTime.ToLongTimeString();
btn_delete.Text = "Delete";
btn_delete.Click += new EventHandler(btn_delete_Click);
td1.Controls.Add(name);
td2.Controls.Add(size);
td3.Controls.Add(dateMod);
td4.Controls.Add(btn_delete);
tr.Controls.Add(td1);
tr.Controls.Add(td2);
tr.Controls.Add(td3);
tr.Controls.Add(td4);
}
filePanel.Controls.Add(fileTable);
}
protected void btn_delete_Click(object sender, EventArgs e)
{
//Delete file
}
Now I want to delete the file when I click on the corresponding delete button. But problem is how will computer know which file to be deleted? I must pass the filename to the delete method.