Example #1
0
        /// <summary>
        /// Save the current state of the loader. If the user loaded the file
        /// or saved once before, then he doesn't need to select a file again.
        /// Unless this is being called as a result of "Save As..." being clicked,
        /// in which case forceFilePrompt will be true.
        /// </summary>
        public void Save(bool forceFilePrompt)
        {
            try
            {
                Flush();


                // Write out our xmlDocument to a file.
                StringWriter  sw  = new StringWriter();
                XmlTextWriter xtw = new XmlTextWriter(sw);

                xtw.Formatting = Formatting.Indented;
                xmlDocument.WriteTo(xtw);

                // Get rid of our artificial super-root before we save out
                // the XML.
                //
                string cleanup = sw.ToString().Replace("<DOCUMENT_ELEMENT>", "");

                cleanup = cleanup.Replace("</DOCUMENT_ELEMENT>", "");
                xtw.Close();
                MemoryStream s    = new MemoryStream();
                StreamWriter file = new StreamWriter(s);

                file.Write(cleanup);

                file.Close();
                SaveLoadLayout.SaveToDB(FormName, s);
                unsaved = false;
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error during save: " + ex.ToString());
            }
        }
Example #2
0
        /// <summary>
        /// Save the current state of the loader. If the user loaded the file
        /// or saved once before, then he doesn't need to select a file again.
        /// Unless this is being called as a result of "Save As..." being clicked,
        /// in which case forceFilePrompt will be true.
        /// </summary>
        public void Save(bool forceFilePrompt)
        {
            try
            {
                Flush();

                // Write out our xmlDocument to a file.
                StringWriter  sw  = new StringWriter();
                XmlTextWriter xtw = new XmlTextWriter(sw);

                xtw.Formatting = Formatting.Indented;
                xmlDocument.WriteTo(xtw);

                // Get rid of our artificial super-root before we save out
                // the XML.
                //
                string cleanup = sw.ToString().Replace("<DOCUMENT_ELEMENT>", "");

                cleanup = cleanup.Replace("</DOCUMENT_ELEMENT>", "");
                xtw.Close();

                MemoryStream s    = new MemoryStream();
                StreamWriter file = new StreamWriter(s);

                file.Write(cleanup);
                file.Close();
                SaveLoadLayout.SaveToDB(FormName, s);
                //int filterIndex = 3;

                //if ((fileName == null) || forceFilePrompt)
                //{
                //    SaveFileDialog dlg = new SaveFileDialog();

                //    dlg.DefaultExt = "xml";
                //    dlg.Filter = "XML Files|*.xml";
                //    if (dlg.ShowDialog() == DialogResult.OK)
                //    {
                //        fileName = dlg.FileName;
                //        filterIndex = dlg.FilterIndex;
                //    }
                //}

                //if (fileName != null)
                //{
                //    switch (filterIndex)
                //    {
                //        case 1 :
                //            {
                //                // Write out our xmlDocument to a file.
                //                StringWriter sw = new StringWriter();
                //                XmlTextWriter xtw = new XmlTextWriter(sw);

                //                xtw.Formatting = Formatting.Indented;
                //                xmlDocument.WriteTo(xtw);

                //                // Get rid of our artificial super-root before we save out
                //                // the XML.
                //                //
                //                string cleanup = sw.ToString().Replace("<DOCUMENT_ELEMENT>", "");

                //                cleanup = cleanup.Replace("</DOCUMENT_ELEMENT>", "");
                //                xtw.Close();

                //                StreamWriter file = new StreamWriter(fileName);

                //                file.Write(cleanup);
                //                file.Close();
                //            }
                //            break;
                //    }
                unsaved = false;
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during save: " + ex.ToString());
            }
        }