コード例 #1
0
        internal static bool GetLastPath(out string lastPath)
        {
            string path = Path.Combine(GetConfigurationPath(), "last-path.xml");

            if (File.Exists(path))
            {
                try
                {
                    LastDatabase ld = new LastDatabase();

                    XmlSerializer xsr = new XmlSerializer(ld.GetType());
                    XmlReaderSettings xrs = new XmlReaderSettings();
                    xrs.CloseInput = true;
                    using (XmlReader xr = XmlReader.Create(path, xrs))
                    {
                        ld = (LastDatabase)xsr.Deserialize(xr);
                    }

                    lastPath = ld.Path;
                    return true;
                } catch (Exception)
                {
                    lastPath = "";
                    return false;
                }
            }
            else
            {
                lastPath = "";
                return false;
            }
        }
コード例 #2
0
        internal static void SaveLastLocation(string databasePath)
        {
            string path = Path.Combine(GetConfigurationPath(), "last-path.xml");

            try
            {
                LastDatabase ld = new LastDatabase();
                ld.Path = databasePath;

                XmlSerializer xsr = new XmlSerializer(ld.GetType());
                XmlWriterSettings xws = new XmlWriterSettings();
                xws.Indent = true;
                xws.IndentChars = "\t";
                xws.CloseOutput = true;
                using (XmlWriter xw = XmlWriter.Create(path, xws))
                {
                    xsr.Serialize(xw, ld);
                }

            } catch (Exception)
            {

            }
        }