I have a Windows Form program that you enter data in to, that data can be saved to a XML format file, I am giving it my own extention of .WSDA, I'd like to be able to without having the program loaded, click this file and have it run the same routine i use to save it.
Here are the events for saving and loading the files via button...
private void button11_Click(object sender, EventArgs e)
{
// Opens Dialog Box
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Workspace Data File |*.wsda";
saveFileDialog1.Title = "Save current Workspace data.";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
// Create an instance of the FormData class and populate it with form data..
FormData FormSave = new FormData();
FormSave.form_type = textForm.Text;
FormSave.policy_num = textPolicynum.Text;
FormSave.effective_date = textEffdate.Text;
FormSave.sai_number = textSAI.Text;
FormSave.office_code = textOffice.Text;
FormSave.change_date = textChgdate.Text;
FormSave.name_insured = textNamedIns.Text;
FormSave.error_code = textErrorCode.Text;
FormSave.producer_code = textProducer.Text;
FormSave.nticid = textNtic.Text;
FormSave.notes = textNotes.Text;
// Create and XmlSerializer to serialize the data.
XmlSerializer xs = new XmlSerializer(typeof(FormData));
// XmlTextWriter writes file.
XmlTextWriter xtw = new XmlTextWriter(new StreamWriter(saveFileDialog1.FileName));
xs.Serialize(xtw, FormSave);
// Stop writing to file.
xtw.Flush();
xtw.Close();
}
}
private void button12_Click(object sender, EventArgs e)
{
// Opens Dialog Box
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Workspace Data File |*.wsda";
openFileDialog1.Title = "Save current Workspace data.";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
//XmlTextReader Reads file.
XmlSerializer xs = new XmlSerializer(typeof(FormData));
XmlTextReader xtw = new XmlTextReader(openFileDialog1.FileName);
FormData FormLoad = new FormData();
//Converts it to form data again.
FormLoad = xs.Deserialize(xtw) as FormData;
//Updates the fields with the data file.
textForm.Text = FormLoad.form_type;
textPolicynum.Text = FormLoad.policy_num;
textEffdate.Text = FormLoad.effective_date;
textSAI.Text = FormLoad.sai_number;
textOffice.Text = FormLoad.office_code;
textProducer.Text = FormLoad.producer_code;
textChgdate.Text = FormLoad.change_date;
textNamedIns.Text = FormLoad.name_insured;
textErrorCode.Text = FormLoad.error_code;
textNtic.Text = FormLoad.nticid;
textNotes.Text = FormLoad.notes;
// Stop Reading File.
xtw.Close();
}
}