Exemplo n.º 1
0
        private bool LoadDefaultSelection(string strFileName)
        {
            //System::String^ strDataPath=Environment::GetFolderPath(Environment::SpecialFolder::ApplicationData);
            string strDataPath = GetAssemblyDirectory();   //Changed to Installed Directory TOM

            strDataPath += "\\";

            Stream stream = null;

            try
            {
                //SoapFormatter^ formatter = gcnew SoapFormatter;
                XmlSerializer formatter = new XmlSerializer(LastSavedSelectionItem.GetType());

                stream = System.IO.File.Open(strDataPath + strFileName, System.IO.FileMode.Open);
                //formatter = new BinaryFormatter();
                LastSavedSelectionItem = (SelectionItem)formatter.Deserialize(stream);
                stream.Close();

                return(true);
            }
            catch (Exception)
            {
                //System::Windows::Forms::MessageBox::Show(Ex->Message);
                if (stream != null)
                {
                    stream.Close();
                }
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool SaveSelection(string strFileName)
        {
            string strDataPath = GetAssemblyDirectory();   //Changed to Installed Directory TOM

            strDataPath += "\\";

            Stream stream = null;

            try
            {
                //Opens a file and serializes the object into it in binary format.
                stream = File.Open(strDataPath + strFileName, FileMode.Create);
                //SoapFormatter^ formatter = gcnew SoapFormatter;

                XmlSerializer formatter = new XmlSerializer(LastSavedSelectionItem.GetType());


                //BinaryFormatter* formatter = new BinaryFormatter();
                formatter.Serialize(stream, LastSavedSelectionItem);
                stream.Close();

                return(true);
            }
            catch (Exception)
            {
                //System::Windows::Forms::MessageBox::Show(Ex->Message);
                if (stream != null)
                {
                    stream.Close();
                }
                return(false);
            }
            return(false);
        }