/// <summary> /// Method to import a text file and generate list view row /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImport_Click(object sender, RoutedEventArgs e) { string fileName; // local variable OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension Nullable <bool> result = openFileDialog1.ShowDialog(); try { if (result == true) //Dialog box to open the xml file { fileName = openFileDialog1.FileName; //retrieve filename and path Invoice newInvoice = new Invoice(); //initiate object InvoiceReader newDocument = new InvoiceReader(fileName, newInvoice); newDocument.ReadInvoice(); newInvoice.NumberOfItems = newDocument.TotalNumberItems(); lstInvoices.Items.Add(new MyItem { ID = newInvoice.InvoiceNumber.ToString(), Company = newInvoice.CompanyDebtorName, NumberOfItems = newInvoice.NumberOfItems.ToString(), ContactPerson = newInvoice.DebtorContactPerson, DueDate = newInvoice.DueDate.ToString("yyyy-MM-dd"), TotalAmount = newInvoice.TotalInvoice().ToString("F") }); lstInvoices.ScrollIntoView(lstInvoices.Items[lstInvoices.Items.Count - 1]); addInvoiceToLibrary.AddElement(newInvoice); } } catch (Exception error) { MessageBox.Show(error.Message + "Environment.NewLine" + error.StackTrace, "Error"); } finally { } }