Example #1
0
        private void newBtn_Click(object sender, EventArgs e)
        {
            string folderLocal = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string folderProgram = System.IO.Path.Combine(folderLocal, "Digital Flash Cards");

            //Use dialog method to show form modally
            dialogCreate dialog = new dialogCreate();
            dialog.ShowDialog(this);
            if (dialog.DialogResult == DialogResult.OK)
            {
                //Get and set the user entered text from the dialog form into variable
                selectedFolder = dialog.subName;
                //Create a new sub folder in the folder directory for the program
                DirectoryInfo subDirectory = new DirectoryInfo(folderProgram);
                subDirectory.CreateSubdirectory(selectedFolder);
                string subFolderPath = System.IO.Path.Combine(folderProgram, selectedFolder);

                //Create text files in new sub folder and properly closes them after creation
                FileInfo queFile = new FileInfo(System.IO.Path.Combine(subFolderPath, "questions.txt"));
                using (FileStream fs = queFile.Create())
                {
                    fs.Close();
                }
                FileInfo ansFile = new FileInfo(System.IO.Path.Combine(subFolderPath, "answers.txt"));
                using (FileStream fs = ansFile.Create())
                {
                    fs.Close();
                }

                //Close dialog box with dialog.OK
                this.DialogResult = DialogResult.OK;
            }
            dialog.Dispose();
        }
Example #2
0
        private void createCardsDialog()
        {
            string folderLocal = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string folderProgram = System.IO.Path.Combine(folderLocal, "Digital Flash Cards");

            //Use dialog method to show form modally
            dialogCreate dialog = new dialogCreate();
            dialog.ShowDialog(this);
            if (dialog.DialogResult == DialogResult.OK)
            {
                //Get and set the user entered text from the dialog form into variable
                currentFolder = dialog.subName;

                //Create a new sub folder in the folder directory for the program
                DirectoryInfo subDirectory = new DirectoryInfo(folderProgram);
                subDirectory.CreateSubdirectory(currentFolder);
                string subFolderPath = System.IO.Path.Combine(folderProgram, currentFolder);

                //Create text files in new sub folder and properly closes them after creation
                FileInfo queFile = new FileInfo(System.IO.Path.Combine(subFolderPath, "questions.txt"));
                using (FileStream fs = queFile.Create())
                {
                    fs.Close();
                }
                FileInfo ansFile = new FileInfo(System.IO.Path.Combine(subFolderPath, "answers.txt"));
                using (FileStream fs = ansFile.Create())
                {
                    fs.Close();
                }
            }
            else if (dialog.DialogResult == DialogResult.Cancel)
            {
                //Creates a recursive process where user must enter text
                this.Close();
            }
            dialog.Dispose();
        }