Beispiel #1
0
        //Запуск создания файла
        private string RunCreateFile(string initial)
        {
            var op = new OpenFileDialog
            {
                CheckFileExists = false,
                AddExtension    = true,
                DefaultExt      = Extension,
                Multiselect     = false,
                FileName        = "NewFile." + Extension,
                Title           = DialogTitle,
                Filter          = DialogFilter
            };

            op.ShowDialog();
            try
            {
                if (op.FileName.IsEmpty())
                {
                    return(initial);
                }
                if (TemplateFile != null)
                {
                    var f = new FileInfo(op.FileName);
                    if (!f.Exists || Different.MessageQuestion("По указанному пути файл уже существует. Заменить файл на новый?"))
                    {
                        if (!f.Directory.Exists)
                        {
                            f.Directory.Create();
                        }
                        var fnew = new FileInfo(TemplateFile);
                        fnew.CopyTo(f.FullName, true);
                    }
                }
                return(op.FileName);
            }
            catch (Exception ex)
            {
                ex.MessageError(ErrorMessage);
                return(initial);
            }
        }
Beispiel #2
0
        //Запуск открытия файла
        private string RunOpenFile(string initial)
        {
            var op = new OpenFileDialog
            {
                AddExtension    = true,
                CheckFileExists = true,
                DefaultExt      = Extension,
                Multiselect     = false,
                Title           = DialogTitle,
                Filter          = DialogFilter
            };

            op.ShowDialog();
            if (op.FileName.IsEmpty())
            {
                return(initial);
            }
            if (FileTables != null && !DaoDb.Check(op.FileName, FileTables))
            {
                Different.MessageError(ErrorMessage, op.FileName);
                return(initial);
            }
            return(op.FileName);
        }