Exemple #1
0
        /// <summary>
        /// Get path to load data.
        /// </summary>
        /// <param name="fileDialogInfo"></param>
        public static Boolean GetPathForLoad
        (
            FileDialogInfo fileDialogInfo
        )
        {
            Boolean forceNew    = false;
            Boolean returnValue = default(Boolean);

            returnValue = GetPathForLoad(fileDialogInfo, forceNew);

            return(returnValue);
        }
Exemple #2
0
        /// <summary>
        /// Get path to save data.
        /// </summary>
        /// <param name="fileDialogInfo"></param>
        public static Boolean GetPathForSave
        (
            FileDialogInfo fileDialogInfo
        )
        {
            Boolean forceDialog = true;
            Boolean returnValue = default(Boolean);

            returnValue = GetPathForSave(fileDialogInfo, forceDialog);

            return(returnValue);
        }
Exemple #3
0
        /// <summary>
        /// Get path to load data.
        /// </summary>
        /// <param name="fileDialogInfo"></param>
        /// <param name="forceNew"></param>
        public static Boolean GetPathForLoad
        (
            FileDialogInfo fileDialogInfo,
            Boolean forceNew
        )
        {
            Boolean returnValue = default(Boolean);

            try
            {
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    if (forceNew)
                    {
                        fileDialogInfo.Filename = fileDialogInfo.NewFilename;

                        returnValue = true;
                    }
                    else
                    {
                        String PreviousFileName = fileDialogInfo.Filename;

                        //define location of file for settings by prompting user for filename.
                        openFileDialog.AutoUpgradeEnabled = true;
                        openFileDialog.CheckFileExists    = true;
                        openFileDialog.CheckPathExists    = true;
                        openFileDialog.DefaultExt         = fileDialogInfo.Extension;
                        openFileDialog.DereferenceLinks   = true;
                        openFileDialog.Filter             = fileDialogInfo.Filters;
                        openFileDialog.Multiselect        = fileDialogInfo.Multiselect;
                        openFileDialog.RestoreDirectory   = true;
                        openFileDialog.ShowHelp           = true;
                        openFileDialog.ShowReadOnly       = false;
                        openFileDialog.ValidateNames      = true;
                        openFileDialog.FileName           = PreviousFileName;
                        openFileDialog.FileNames[0]       = fileDialogInfo.Filename;
                        //openFileDialog.InitialDirectory = (fileDialogInfo.InitialDirectory == default(Environment.SpecialFolder) ? fileDialogInfo.CustomInitialDirectory : Environment.GetFolderPath(Environment.SpecialFolder.Personal).WithTrailingSeparator());
                        openFileDialog.InitialDirectory = PathExtensions.WithTrailingSeparator((fileDialogInfo.InitialDirectory == default(Environment.SpecialFolder) ? fileDialogInfo.CustomInitialDirectory : Environment.GetFolderPath(Environment.SpecialFolder.Personal)));

                        DialogResult dialogResult = openFileDialog.ShowDialog();

                        switch (dialogResult)
                        {
                        case DialogResult.OK:
                        {
                            fileDialogInfo.Filename  = openFileDialog.FileName;
                            fileDialogInfo.Filenames = openFileDialog.FileNames;

                            returnValue = true;

                            break;
                        }

                        case DialogResult.Cancel:
                        {
                            break;
                        }

                        default:
                        {
                            throw new InvalidEnumArgumentException();
                        }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }

            return(returnValue);
        }
Exemple #4
0
        /// <summary>
        /// Get path to save data.
        /// </summary>
        /// <param name="fileDialogInfo"></param>
        /// <param name="forceDialog"></param>
        public static Boolean GetPathForSave
        (
            FileDialogInfo fileDialogInfo,
            Boolean forceDialog
        )
        {
            Boolean returnValue = default(Boolean);

            try
            {
                using (SaveFileDialog saveFileDialog = new SaveFileDialog())
                {
                    //if ((fileDialogInfo.Filename == fileDialogInfo.NewFilename) || (forceDialog))
                    if ((fileDialogInfo.Filename.EndsWith(fileDialogInfo.NewFilename)) || (forceDialog))
                    {
                        //define location of file for settings by prompting user for filename.
                        saveFileDialog.AddExtension       = true;
                        saveFileDialog.AutoUpgradeEnabled = true;
                        saveFileDialog.CheckPathExists    = true;
                        saveFileDialog.CreatePrompt       = false;
                        saveFileDialog.OverwritePrompt    = true;
                        saveFileDialog.ValidateNames      = true;
                        saveFileDialog.ShowHelp           = true;
                        saveFileDialog.DefaultExt         = fileDialogInfo.Extension;
                        saveFileDialog.FileName           = fileDialogInfo.Filename;
                        saveFileDialog.Filter             = fileDialogInfo.Filters;
                        saveFileDialog.FilterIndex        = 1;
                        //saveFileDialog.InitialDirectory = (fileDialogInfo.InitialDirectory == default(Environment.SpecialFolder) ? fileDialogInfo.CustomInitialDirectory : Environment.GetFolderPath(Environment.SpecialFolder.Personal).WithTrailingSeparator());
                        saveFileDialog.InitialDirectory = PathExtensions.WithTrailingSeparator((fileDialogInfo.InitialDirectory == default(Environment.SpecialFolder) ? fileDialogInfo.CustomInitialDirectory : Environment.GetFolderPath(Environment.SpecialFolder.Personal)));

                        DialogResult dialogResult = saveFileDialog.ShowDialog();

                        switch (dialogResult)
                        {
                        case DialogResult.OK:
                        {
                            if (Path.GetFileName(saveFileDialog.FileName).ToLower() == (fileDialogInfo.NewFilename + "." + fileDialogInfo.Extension).ToLower())
                            {
                                //user did not select or enter a name different than new; for now I have chosen not to allow that name to be used for a file.--SJS, 12/16/2005
                                MessageBox.Show("The name \"" + (fileDialogInfo.NewFilename + "." + fileDialogInfo.Extension).ToLower() + "\" is not allowed; please choose another. Settings not saved.", fileDialogInfo.Title);
                            }
                            else
                            {
                                //set new filename
                                fileDialogInfo.Filename  = saveFileDialog.FileName;
                                fileDialogInfo.Filenames = saveFileDialog.FileNames;

                                returnValue = true;
                            }

                            break;
                        }

                        case DialogResult.Cancel:
                        {
                            break;
                        }

                        default:
                        {
                            throw new InvalidEnumArgumentException();
                        }
                        }
                    }
                    else
                    {
                        returnValue = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }

            return(returnValue);
        }