// Save file private void Save_OnClick(object sender, RoutedEventArgs e) { // Set the button as a save file dialog when clicked SaveFileDialog saveDlg = new SaveFileDialog { // Set the filter so the user will know which format of STL will be saved Filter = "ASCII STL File (*.stl)|*.stl|Binary STL File (*.stl)|*.stl", // Set the initial directory of the saved file to My Documents InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), }; // Instantiate DataWriter to access its methods DataWriter dw = new DataWriter(); // Requirements to save the file bool reqA = saveDlg.ShowDialog() == true; // To open the Save Dialog bool reqB = saveDlg.FilterIndex == 1; // If the user wants to save the file as an ASCII STL File if (STLFile != null) { if (reqA && reqB) { // AsAsciiFile here with SaveDlg.Filename and data model as parameter dw.AsAsciiFile(saveDlg.FileName, STLFile); MessageBox.Show("File saved as an ASCII STL File.", "Successful!"); } else // If the user wants to save the DataStructure as a binary STL File (FilterIndex == 2) { // AsBinaryFile here with SaveDlg.Filename and data model as parameter dw.AsBinaryFile(saveDlg.FileName, STLFile); MessageBox.Show("File saved as a binary STL File.", "Successful!"); } } else { MessageBox.Show("No STL file exist. \nPlease open a valid file first.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }