Esempio n. 1
0
        // If it's necessary to throw up a "This file exists, are you sure?" kind of
        // MessageBox, here's where we do it
        // Return value is whether or not the user hit "okay".
        internal virtual bool PromptUserIfAppropriate(string fileName)
        {
            if ((options & NativeMethods.OFN_FILEMUSTEXIST) != 0)
            {
                bool fileExists = false;

                // SECREVIEW : We must Assert just to check if the file exists. Since
                //           : we are doing this as part of the FileDialog, this is
                //           : OK.
                //
                new FileIOPermission(FileIOPermissionAccess.Read, IntSecurity.UnsafeGetFullPath(fileName)).Assert();
                try {
                    fileExists = File.Exists(fileName);
                }
                finally {
                    CodeAccessPermission.RevertAssert();
                }

                if (!fileExists)
                {
                    PromptFileNotFound(fileName);
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        public Stream OpenFile()
        {
            Debug.WriteLineIf(IntSecurity.SecurityDemand.TraceVerbose, "FileDialogOpenFile Demanded");
            IntSecurity.FileDialogOpenFile.Demand();

            string filename = FileNamesInternal[0];

            if (filename == null || (filename.Length == 0))
            {
                throw new ArgumentNullException("FileName");
            }

            Stream s = null;

            // SECREVIEW : We demanded the FileDialog permission above, so it is safe
            //           : to assert this here. Since the user picked the file, it
            //           : is OK to give them readonly access to the stream.
            //
            new FileIOPermission(FileIOPermissionAccess.Read, IntSecurity.UnsafeGetFullPath(filename)).Assert();
            try
            {
                s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            return(s);
        }
Esempio n. 3
0
        public Stream OpenFile()
        {
            Debug.WriteLineIf(IntSecurity.SecurityDemand.TraceVerbose, "FileDialogOpenFile Demanded");
            IntSecurity.FileDialogOpenFile.Demand();

            string filename = FileNamesInternal[0];

            if (filename == null || (filename.Length == 0))
            {
                throw new ArgumentNullException(nameof(FileName));
            }

            Stream s = null;

            //



            new FileIOPermission(FileIOPermissionAccess.Read, IntSecurity.UnsafeGetFullPath(filename)).Assert();
            try
            {
                s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            return(s);
        }
Esempio n. 4
0
        public Stream OpenFile()
        {
            Debug.WriteLineIf(IntSecurity.SecurityDemand.TraceVerbose, "FileDialogSaveFile Demanded");
            IntSecurity.FileDialogSaveFile.Demand();

            string filename = FileNamesInternal[0];

            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("FileName");
            }

            Stream s = null;

            //



            new FileIOPermission(FileIOPermissionAccess.AllAccess, IntSecurity.UnsafeGetFullPath(filename)).Assert();
            try {
                s = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite);
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            return(s);
        }
Esempio n. 5
0
        internal static bool FileExists(string fileName)
        {
            bool fileExists = false;

            try {
                // SECREVIEW : We must Assert just to check if the file exists. Since
                //           : we are doing this as part of the FileDialog, this is OK.
                new FileIOPermission(FileIOPermissionAccess.Read, IntSecurity.UnsafeGetFullPath(fileName)).Assert();
                try {
                    fileExists = File.Exists(fileName);
                }
                finally {
                    CodeAccessPermission.RevertAssert();
                }
            }
            catch (System.IO.PathTooLongException) {
            }
            return(fileExists);
        }
Esempio n. 6
0
        internal static bool FileExists(string fileName)
        {
            bool fileExists = false;

            try {
                //

                new FileIOPermission(FileIOPermissionAccess.Read, IntSecurity.UnsafeGetFullPath(fileName)).Assert();
                try {
                    fileExists = File.Exists(fileName);
                }
                finally {
                    CodeAccessPermission.RevertAssert();
                }
            }
            catch (System.IO.PathTooLongException) {
            }
            return(fileExists);
        }