Reputation: 347
i want to upload files in a folder and then display that files in datagridview
1) upload files to a folder
2) display that files in datagridview
can any one help me
Upvotes: 1
Views: 3025
Reputation: 125322
Try putting this code in your form class and then extend it as you want:
public string Path { get; set; }
private void UploadButton_Click(object sender, EventArgs e)
{
var o = new OpenFileDialog();
o.Multiselect = true;
if(o.ShowDialog()== System.Windows.Forms.DialogResult.OK)
{
o.FileNames.ToList().ForEach(file=>{
System.IO.File.Copy(file, System.IO.Path.Combine(this.Path, System.IO.Path.GetFileName(file)));
});
}
this.LoadFiles();
}
private void Form_Load(object sender, EventArgs e)
{
this.LoadFiles();
}
private void LoadFiles()
{
this.Path = @"d:\Test";
var files = System.IO.Directory.GetFiles(this.Path);
this.dataGridView1.DataSource = files.Select(file => new { Name = System.IO.Path.GetFileName(file), Path = file }).ToList();
}
And here is screenshot:
Upvotes: 2