예제 #1
0
        /// <summary>
        /// Configures the file dialog.
        /// </summary>
        /// <param name="fileDialog">The file dialog.</param>
        /// <param name="context">The determine file context.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="fileDialog"/> is <c>null</c>.</exception>
        protected virtual void ConfigureFileDialog(FileDialog fileDialog, DetermineFileContext context)
        {
            Argument.IsNotNull("fileDialog", fileDialog);
            Argument.IsNotNull("context", context);

            fileDialog.Filter   = context.Filter;
            fileDialog.FileName = context.FileName;

            fileDialog.AddExtension     = context.AddExtension;
            fileDialog.CheckFileExists  = context.CheckFileExists;
            fileDialog.CheckPathExists  = context.CheckPathExists;
            fileDialog.FilterIndex      = context.FilterIndex;
            fileDialog.InitialDirectory = GetInitialDirectory(context);
            fileDialog.Title            = context.Title;
            fileDialog.ValidateNames    = context.ValidateNames;
        }
예제 #2
0
        /// <summary>
        /// Gets the initial directory used for the file dialog.
        /// <para />
        /// The default implementation not only uses the <see cref="InitialDirectory"/> property, but also
        /// checks whether it actually exists on disk to prevent exceptions.
        /// </summary>
        /// <returns>The inital directory.</returns>
        protected virtual string GetInitialDirectory(DetermineFileContext context)
        {
            Argument.IsNotNull(nameof(context), context);

            var initialDirectory = context.InitialDirectory;

            if (!string.IsNullOrWhiteSpace(initialDirectory))
            {
                if (!Directory.Exists(initialDirectory))
                {
                    initialDirectory = null;
                }
                else
                {
                    initialDirectory = IO.Path.AppendTrailingSlash(initialDirectory);
                }
            }

            return(initialDirectory);
        }