コード例 #1
0
        /// <summary>
        /// Opens up the dialog for creating a new password file
        /// Returns true upon success and false upon premature closing.
        /// </summary>
        public static bool CreateFile()
        {
            Stream myStream;
            //default to creating a .csv file
            SaveFileDialog save = new SaveFileDialog {
                Filter = "CSV |*.csv",
                Title  = "Save password DB"
            };

            //opens up the file explorer dialog menu and determines if the result is the ok button
            if (save.ShowDialog() == DialogResult.OK)
            {
                //as long as the stream is not null load the file name and optionally print it for testing purposes
                if ((myStream = save.OpenFile()) != null)
                {
                    FileOP.LoadFile(save.FileName);
                    FileOP.PrintFileName();
                    myStream.Close();
                }
                //Write the first line of the file to the file.
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(save.FileName, true)) {
                    file.WriteLine("Expiration Date,Title,UserName,Password,URL,Notes");
                    file.Close();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }