Ejemplo n.º 1
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);
        }
Ejemplo 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(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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }