I'll start by noting that I'm a complete beginner to C# and I've been trying to "learn by doing."
The overall project is a media player that I'm creating and augmenting from a couple of YouTube videos I've been watching. I'm at a point where I'd like to understand the SaveFileDialog and how to save items from a ListBox into an xml file.
Before I can get there, however, I'm having trouble with just getting the SaveFileDialog to save anything at all and then close.
Here's the code I'm working with:
public Form1()
{
InitializeComponent();
}
private void btn_save_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "XML-File | *.xml";
saveFileDialog1.Title = "Save Playlist";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK) ;
}
Right now, when I click the "Save" button (btn_save), the Save dialog will open and it will default to an xml file, but no file will save after clicking Save, and then after clicking Save, the dialog just opens again and again until I select Cancel.
If I try to add
SaveFileDialog.Close();
I get an error saying "SaveFileDialog" does not contain a definition for 'Close', but I figure I've got to set something that tells the dialog to close after hitting Save.
What will help me most here is the "fix" for this and then some comments in the code that explain what's occurring on each line so that I perform more relevant searches and read further.
That said, any help with this would be appreciated. Please let me know if I need to include additional code in this example.