Esempio n. 1
0
        /// <include file='doc\OpenFileDialog.uex' path='docs/doc[@for="OpenFileDialog.RunFileDialog"]/*' />
        /// <devdoc>
        ///     Displays a file open dialog.
        /// </devdoc>
        /// <internalonly/>
        internal override bool RunFileDialog(NativeMethods.OPENFILENAME_I ofn)
        {
            //We have already done the demand in EnsureFileDialogPermission but it doesn't hurt to do it again
            Debug.WriteLineIf(IntSecurity.SecurityDemand.TraceVerbose, "FileDialogOpenFile Demanded in OpenFileDialog.RunFileDialog");
            IntSecurity.FileDialogOpenFile.Demand();

            bool result = UnsafeNativeMethods.GetOpenFileName(ofn);

            if (!result)
            {
                // Something may have gone wrong - check for error condition
                //
                int errorCode = SafeNativeMethods.CommDlgExtendedError();
                switch (errorCode)
                {
                case NativeMethods.FNERR_INVALIDFILENAME:
                    throw new InvalidOperationException(SR.GetString(SR.FileDialogInvalidFileName, FileName));

                case NativeMethods.FNERR_SUBCLASSFAILURE:
                    throw new InvalidOperationException(SR.GetString(SR.FileDialogSubLassFailure));

                case NativeMethods.FNERR_BUFFERTOOSMALL:
                    throw new InvalidOperationException(SR.GetString(SR.FileDialogBufferTooSmall));
                }
            }
            return(result);
        }
        internal override bool RunFileDialog(NativeMethods.OPENFILENAME_I ofn)
        {
            System.Windows.Forms.IntSecurity.FileDialogSaveFile.Demand();
            bool saveFileName = System.Windows.Forms.UnsafeNativeMethods.GetSaveFileName(ofn);

            if (!saveFileName && (SafeNativeMethods.CommDlgExtendedError() == 0x3002))
            {
                throw new InvalidOperationException(System.Windows.Forms.SR.GetString("FileDialogInvalidFileName", new object[] { base.FileName }));
            }
            return(saveFileName);
        }
Esempio n. 3
0
        /// <include file='doc\SaveFileDialog.uex' path='docs/doc[@for="SaveFileDialog.RunFileDialog"]/*' />
        /// <devdoc>
        /// </devdoc>
        /// <internalonly/>
        internal override bool RunFileDialog(NativeMethods.OPENFILENAME_I ofn)
        {
            bool result = UnsafeNativeMethods.GetSaveFileName(ofn);

            if (!result)
            {
                // Something may have gone wrong - check for error condition
                //
                int errorCode = SafeNativeMethods.CommDlgExtendedError();
                switch (errorCode)
                {
                case NativeMethods.FNERR_INVALIDFILENAME:
                    throw new InvalidOperationException(string.Format(SR.FileDialogInvalidFileName, FileName));
                }
            }

            return(result);
        }
Esempio n. 4
0
        internal override bool RunFileDialog(NativeMethods.OPENFILENAME_I ofn)
        {
            System.Windows.Forms.IntSecurity.FileDialogOpenFile.Demand();
            bool openFileName = System.Windows.Forms.UnsafeNativeMethods.GetOpenFileName(ofn);

            if (!openFileName)
            {
                switch (SafeNativeMethods.CommDlgExtendedError())
                {
                case 0x3001:
                    throw new InvalidOperationException(System.Windows.Forms.SR.GetString("FileDialogSubLassFailure"));

                case 0x3002:
                    throw new InvalidOperationException(System.Windows.Forms.SR.GetString("FileDialogInvalidFileName", new object[] { base.FileName }));

                case 0x3003:
                    throw new InvalidOperationException(System.Windows.Forms.SR.GetString("FileDialogBufferTooSmall"));
                }
            }
            return(openFileName);
        }
Esempio n. 5
0
        /// <include file='doc\OpenFileDialog.uex' path='docs/doc[@for="OpenFileDialog.RunFileDialog"]/*' />
        /// <devdoc>
        ///     Displays a file open dialog.
        /// </devdoc>
        /// <internalonly/>
        internal override bool RunFileDialog(NativeMethods.OPENFILENAME_I ofn)
        {
            bool result = UnsafeNativeMethods.GetOpenFileName(ofn);

            if (!result)
            {
                // Something may have gone wrong - check for error condition
                //
                int errorCode = SafeNativeMethods.CommDlgExtendedError();
                switch (errorCode)
                {
                case NativeMethods.FNERR_INVALIDFILENAME:
                    throw new InvalidOperationException(string.Format(SR.FileDialogInvalidFileName, FileName));

                case NativeMethods.FNERR_SUBCLASSFAILURE:
                    throw new InvalidOperationException(SR.FileDialogSubLassFailure);

                case NativeMethods.FNERR_BUFFERTOOSMALL:
                    throw new InvalidOperationException(SR.FileDialogBufferTooSmall);
                }
            }
            return(result);
        }