недавно я внес некоторые изменения в событие кнопки "сохранить", и оно просто больше не записывает файл XML или не создает новый. Кажется, я не могу понять, что здесь не так ... Моя строка пути сохранения выглядит хорошо для меня. Пожалуйста, помогите мне понять, что не так с моим кодом. Большое спасибо.
Вот мой код:
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
string savepath;
SaveFileDialog DialogSave = new SaveFileDialog();
// Default file extension
DialogSave.DefaultExt = "txt";
// Available file extensions
DialogSave.Filter = "XML file (*.xml)|*.xml|All files (*.*)|*.*";
// Adds a extension if the user does not
DialogSave.AddExtension = true;
// Restores the selected directory, next time
DialogSave.RestoreDirectory = true;
// Dialog title
DialogSave.Title = "Where do you want to save the file?";
// Startup directory
DialogSave.InitialDirectory = @"C:/";
if (DialogSave.ShowDialog().Equals(true))
{
savepath = DialogSave.FileName;
//DialogSave.Dispose();
DialogSave = null;
FormSaving formsaving = new FormSaving();
formsaving.Builderemail = comboBox1.SelectedIndex;
formsaving.Manageremail = comboBox2.SelectedIndex;
if (MajorversionresultLabel != null && MajorversionresultLabel.Content != null && MajorversionLabel.Content.ToString() != string.Empty)
formsaving.Majorversion = MajorversionresultLabel.Content.ToString();
if (MinorversionresultLabel != null && MinorversionresultLabel.Content != null && MinorversionLabel.Content.ToString() != string.Empty)
formsaving.Minorversion = MinorversionresultLabel.Content.ToString();
if (ProjectnumberresultLabel != null && ProjectnumberresultLabel.Content != null && ProjectnumberLabel.Content.ToString() != string.Empty)
formsaving.Projectnumber = ProjectnumberresultLabel.Content.ToString();
if (BuildnumberresultLabel != null && BuildnumberresultLabel.Content != null && BuildnumberLabel.Content.ToString() != string.Empty)
formsaving.Buildnumber = BuildnumberresultLabel.Content.ToString();
if (PreviousbuildversionresultLabel != null && PreviousbuildversionresultLabel.Content != null && PreviousbuildversionresultLabel.Content.ToString() != string.Empty)
formsaving.Previousbuildversion = PreviousbuildversionresultLabel.Content.ToString();
formsaving.Startzbuildfrom = StartzbuildfromcomboBox.SelectedIndex;
formsaving.Fullorsingle = FullorsinglecomboBox.SelectedIndex;
formsaving.Builddrive = BuilddrivecomboBox.SelectedIndex;
if (TruecmtipresultTextBlock != null && TruecmtipresultTextBlock.Text != null && TruecmtipresultTextBlock.Text != string.Empty)
formsaving.Truecmtip = TruecmtipresultTextBlock.Text;
formsaving.Truecmcomments = TruecmcommentsresultTextBlock.Text;
...
using (Stream savestream = new FileStream(savepath, FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(FormSaving));
serializer.Serialize(savestream, formsaving);
}
}
DialogSave.Dispose();
}