i have a listview with buttons on each row i want to open csv files of the the name of the row concerned, i match the the name of the fournisseur with the name of the csv file if it's a match the button in the row of this fournisseur should open the file.
here is my code :
private void OpenFile_OnClick(object sender, RoutedEventArgs e) { for (int i = 0; i < listView.Items.Count; i++) { dynamic currentItemInLoop = listView.Items[i]; String frs = (String)currentItemInLoop.fournisseur; DateTime myDate = (DateTime)currentItemInLoop.date; string myPath = @"C:\Users\DefaultAccount\Desktop\Projet Top Of Travel\FichiersCSV\"; string fac = "Facture_"; string filename = string.Format(frs); filename = Regex.Replace(filename + " " + myDate, @"[^0-9a-zA-Z]", " "); string finalPath = System.IO.Path.Combine(myPath, fac + filename + ".csv"); string[] dirs = Directory.GetFiles(@"C:\Users\DefaultAccount\Desktop\Projet Top Of Travel\FichiersCSV\", "*.csv"); if (finalPath.Contains(frs)) { Process.Start(finalPath); } } }
<GridViewColumn Header="Fichier CSV" Width="360"><GridViewColumn.CellTemplate><DataTemplate><Button x:Name="OpenFile" Content="Open File" Click="OpenFile_OnClick" Width="350"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn>