Exemple #1
0
        private DirectoryInfo CreateSubdirectoryHelper(String path, Object directorySecurity)
        {
            Contract.Requires(path != null);

            String newDirs  = Path.InternalCombine(FullPath, path);
            String fullPath = Path.GetFullPathInternal(newDirs);

            if (0 != String.Compare(FullPath, 0, fullPath, 0, FullPath.Length, StringComparison.OrdinalIgnoreCase))
            {
                String displayPath = __Error.GetDisplayablePath(DisplayPath, false);
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSubPath", path, displayPath));
            }

            // Ensure we have permission to create this subdirectory.
            String demandDirForCreation = Directory.GetDemandDir(fullPath, true);

#if FEATURE_CORECLR
            FileSecurityState state = new FileSecurityState(FileSecurityStateAccess.Write, OriginalPath, demandDirForCreation);
            state.EnsureState();
#else
            FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, demandDirForCreation, false, false);
#endif

            Directory.InternalCreateDirectory(fullPath, path, directorySecurity);

            // Check for read permission to directory we hand back by calling this constructor.
            return(new DirectoryInfo(fullPath));
        }
Exemple #2
0
        private void Init(String path, bool checkHost)
        {
            // Special case "<DriveLetter>:" to point to "<CurrentDirectory>" instead
            if ((path.Length == 2) && (path[1] == ':'))
            {
                OriginalPath = ".";
            }
            else
            {
                OriginalPath = path;
            }

            // Must fully qualify the path for the security check
            String fullPath = Path.GetFullPathInternal(path);

            demandDir = new String[] { Directory.GetDemandDir(fullPath, true) };
#if FEATURE_CORECLR
            if (checkHost)
            {
                FileSecurityState state = new FileSecurityState(FileSecurityStateAccess.Read, OriginalPath, fullPath);
                state.EnsureState();
            }
#else
            new FileIOPermission(FileIOPermissionAccess.Read, demandDir, false, false).Demand();
#endif

            FullPath    = fullPath;
            DisplayPath = GetDisplayName(OriginalPath, FullPath);
        }
Exemple #3
0
        public void MoveTo(String destFileName)
        {
            if (destFileName == null)
            {
                throw new ArgumentNullException("destFileName");
            }
            if (destFileName.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName");
            }

            new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { FullPath }, false, false).Demand();
            String fullDestFileName = Path.GetFullPathInternal(destFileName);

            new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullDestFileName }, false, false).Demand();

            if (!Win32Native.MoveFile(FullPath, fullDestFileName))
            {
                __Error.WinIOError();
            }
            FullPath     = fullDestFileName;
            OriginalPath = destFileName;
            _name        = Path.GetFileName(fullDestFileName);

            // Flush any cached information about the file.
            _dataInitialised = -1;
        }
Exemple #4
0
        public void MoveTo(String destFileName)
        {
            if (destFileName == null)
            {
                throw new ArgumentNullException("destFileName");
            }
            if (destFileName.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName");
            }
            Contract.EndContractBlock();

            String fullDestFileName = Path.GetFullPathInternal(destFileName);

#if FEATURE_CORECLR
            FileSecurityState sourceState = new FileSecurityState(FileSecurityStateAccess.Write | FileSecurityStateAccess.Read, DisplayPath, FullPath);
            FileSecurityState destState   = new FileSecurityState(FileSecurityStateAccess.Write, destFileName, fullDestFileName);
            sourceState.EnsureState();
            destState.EnsureState();
#else
            new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { FullPath }, false, false).Demand();
            FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, fullDestFileName, false, false);
#endif

            if (!Win32Native.MoveFile(FullPath, fullDestFileName))
            {
                __Error.WinIOError();
            }
            FullPath     = fullDestFileName;
            OriginalPath = destFileName;
            _name        = Path.GetFileName(fullDestFileName);
            DisplayPath  = GetDisplayPath(destFileName);
            // Flush any cached information about the file.
            _dataInitialised = -1;
        }
Exemple #5
0
        internal FileSystemEnumerableIterator(string path, string originalUserPath, string searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler)
        {
            this.oldMode     = Win32Native.SetErrorMode(1);
            this.searchStack = new List <Directory.SearchData>();
            string str = FileSystemEnumerableIterator <TSource> .NormalizeSearchPattern(searchPattern);

            if (str.Length == 0)
            {
                this.empty = true;
            }
            else
            {
                this._resultHandler = resultHandler;
                this.searchOption   = searchOption;
                this.fullPath       = Path.GetFullPathInternal(path);
                string fullSearchString = FileSystemEnumerableIterator <TSource> .GetFullSearchString(this.fullPath, str);

                this.normalizedSearchPath = Path.GetDirectoryName(fullSearchString);
                string[] pathList = new string[] { Directory.GetDemandDir(this.fullPath, true), Directory.GetDemandDir(this.normalizedSearchPath, true) };
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, pathList, false, false).Demand();
                this.searchCriteria = FileSystemEnumerableIterator <TSource> .GetNormalizedSearchCriteria(fullSearchString, this.normalizedSearchPath);

                string directoryName = Path.GetDirectoryName(str);
                string str4          = originalUserPath;
                if ((directoryName != null) && (directoryName.Length != 0))
                {
                    str4 = Path.Combine(str4, directoryName);
                }
                this.userPath   = str4;
                this.searchData = new Directory.SearchData(this.normalizedSearchPath, this.userPath, searchOption);
                this.CommonInit();
            }
        }
Exemple #6
0
        private static FileStream OpenFile(String path, FileAccess access, out SafeFileHandle handle)
        {
            FileStream fs = new FileStream(path, FileMode.Open, access, FileShare.ReadWrite, 1);

            handle = fs.SafeFileHandle;

            if (handle.IsInvalid)
            {
                // Return a meaningful error, using the RELATIVE path to
                // the file to avoid returning extra information to the caller.

                // NT5 oddity - when trying to open "C:\" as a FileStream,
                // we usually get ERROR_PATH_NOT_FOUND from the OS.  We should
                // probably be consistent w/ every other directory.
                int    hr       = Marshal.GetLastWin32Error();
                String FullPath = Path.GetFullPathInternal(path);
                if (hr == __Error.ERROR_PATH_NOT_FOUND && FullPath.Equals(Directory.GetDirectoryRoot(FullPath)))
                {
                    hr = __Error.ERROR_ACCESS_DENIED;
                }


                __Error.WinIOError(hr, path);
            }
            return(fs);
        }
Exemple #7
0
        public static void Move(String sourceFileName, String destFileName)
        {
            if (sourceFileName == null || destFileName == null)
            {
                throw new ArgumentNullException((sourceFileName == null ? "sourceFileName" : "destFileName"), Environment.GetResourceString("ArgumentNull_FileName"));
            }
            if (sourceFileName.Length == 0 || destFileName.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), (sourceFileName.Length == 0 ? "sourceFileName" : "destFileName"));
            }

            String fullSourceFileName = Path.GetFullPathInternal(sourceFileName);

            new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { fullSourceFileName }, false, false).Demand();
            String fullDestFileName = Path.GetFullPathInternal(destFileName);

            new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullDestFileName }, false, false).Demand();

            if (!InternalExists(fullSourceFileName))
            {
                __Error.WinIOError(Win32Native.ERROR_FILE_NOT_FOUND, fullSourceFileName);
            }

            if (!Win32Native.MoveFile(fullSourceFileName, fullDestFileName))
            {
                __Error.WinIOError();
            }
        }
Exemple #8
0
        public static bool Exists(String path)
        {
            try
            {
                if (path == null)
                {
                    return(false);
                }
                if (path.Length == 0)
                {
                    return(false);
                }

                path = Path.GetFullPathInternal(path);

                new FileIOPermission(FileIOPermissionAccess.Read, new String[] { path }, false, false).Demand();

                return(InternalExists(path));
            }
            catch (ArgumentException) {}
            catch (NotSupportedException) {} // Security can throw this on ":"
            catch (SecurityException) {}
            catch (IOException) {}
            catch (UnauthorizedAccessException) {}

            return(false);
        }
Exemple #9
0
        public static void Delete(String path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            String fullPath = Path.GetFullPathInternal(path);

            // For security check, path should be resolved to an absolute path.
            new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullPath }, false, false).Demand();

            if (Environment.IsWin9X() && Directory.InternalExists(fullPath)) // Win9x fails silently for directories.
            {
                throw new UnauthorizedAccessException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("UnauthorizedAccess_IODenied_Path"), path));
            }

            bool r = Win32Native.DeleteFile(fullPath);

            if (!r)
            {
                int hr = Marshal.GetLastWin32Error();
                if (hr == Win32Native.ERROR_FILE_NOT_FOUND)
                {
                    return;
                }
                else
                {
                    __Error.WinIOError(hr, fullPath);
                }
            }
        }
Exemple #10
0
		/// <include file='doc\DirectoryInfo.uex' path='docs/doc[@for="DirectoryInfo.MoveTo"]/*' />
        public void MoveTo(String destDirName) {
            if (destDirName==null)
                throw new ArgumentNullException("destDirName");
            if (destDirName.Length==0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destDirName");
    		
            new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, demandDir, false, false).Demand();
            String fullDestDirName = Path.GetFullPathInternal(destDirName);
            String demandPath;
            if (!fullDestDirName.EndsWith( '\\'))
                fullDestDirName = fullDestDirName + "\\";

            demandPath = fullDestDirName + ".";

            new FileIOPermission(FileIOPermissionAccess.Write, demandPath).Demand();

            String fullSourcePath;
            if (FullPath.EndsWith( '\\' ))
                fullSourcePath = FullPath;
            else
                fullSourcePath = FullPath + "\\";

            if (CultureInfo.InvariantCulture.CompareInfo.Compare(fullSourcePath, fullDestDirName, CompareOptions.IgnoreCase) == 0)
                throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent"));

            String sourceRoot = Path.GetPathRoot(fullSourcePath);
            String destinationRoot = Path.GetPathRoot(fullDestDirName);

            if (CultureInfo.InvariantCulture.CompareInfo.Compare(sourceRoot, destinationRoot, CompareOptions.IgnoreCase) != 0)
                throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot"));
    		
            if (!Directory.InternalExists(FullPath)) // Win9x hack to behave same as Winnt. 
                throw new DirectoryNotFoundException(String.Format(Environment.GetResourceString("IO.PathNotFound_Path"), destDirName));
    
    		
            if (!Win32Native.MoveFile(FullPath, destDirName))
            {
                int hr = Marshal.GetLastWin32Error();
                if (hr == Win32Native.ERROR_FILE_NOT_FOUND) // Win32 is weird, it gives back a file not found
                {
                    hr = Win32Native.ERROR_PATH_NOT_FOUND;
                    __Error.WinIOError(hr, OriginalPath);
                }
				
                if (hr == Win32Native.ERROR_ACCESS_DENIED) // WinNT throws IOException. Win9x hack to do the same.
                    throw new IOException(String.Format(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path"), OriginalPath));
    		
                __Error.WinIOError(hr,String.Empty);
            }
            FullPath = fullDestDirName;
            OriginalPath = destDirName;
            if (FullPath.EndsWith( '\\' ))
                demandDir = new String[] { FullPath + "." };
            else
                demandDir = new String[] { FullPath + "\\." };

            // Flush any cached information about the directory.
            _dataInitialised = -1;
        }
Exemple #11
0
        public static void SetAccessControl(string path, DirectorySecurity directorySecurity)
        {
            if (directorySecurity == null)
            {
                throw new ArgumentNullException("directorySecurity");
            }
            string fullPathInternal = Path.GetFullPathInternal(path);

            directorySecurity.Persist(fullPathInternal);
        }
Exemple #12
0
        public static void SetAccessControl(string path, FileSecurity fileSecurity)
        {
            if (fileSecurity == null)
            {
                throw new ArgumentNullException("fileSecurity");
            }
            string fullPathInternal = Path.GetFullPathInternal(path);

            fileSecurity.Persist(fullPathInternal);
        }
Exemple #13
0
        private void Init(string fileName, bool checkHost)
        {
            this.OriginalPath = fileName;
            string fullPathInternal = Path.GetFullPathInternal(fileName);

            FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, fullPathInternal, false, false);
            this._name       = Path.GetFileName(fileName);
            this.FullPath    = fullPathInternal;
            this.DisplayPath = this.GetDisplayPath(fileName);
        }
Exemple #14
0
        public static string GetFullPath(string path)
        {
            string fullPathInternal = Path.GetFullPathInternal(path);

            new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new string[1]
            {
                fullPathInternal
            }, 0 != 0, 0 != 0).Demand();
            return(fullPathInternal);
        }
 /// <summary>Initializes a new instance of the <see cref="T:System.IO.FileSystemInfo" /> class with serialized data.</summary>
 /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown. </param>
 /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination. </param>
 /// <exception cref="T:System.ArgumentNullException">The specified <see cref="T:System.Runtime.Serialization.SerializationInfo" /> is null.</exception>
 // Token: 0x060018B7 RID: 6327 RVA: 0x00050C54 File Offset: 0x0004EE54
 protected FileSystemInfo(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     this.FullPath         = Path.GetFullPathInternal(info.GetString("FullPath"));
     this.OriginalPath     = info.GetString("OriginalPath");
     this._dataInitialised = -1;
 }
Exemple #16
0
        //| <include file='doc\Directory.uex' path='docs/doc[@for="Directory.GetDirectoryRoot"]/*' />
        public static String GetDirectoryRoot(String path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            String fullPath = Path.GetFullPathInternal(path);

            return(fullPath.Substring(0, Path.GetRootLength(fullPath)));
        }
        protected FileSystemInfo(SerializationInfo info, StreamingContext context)
        {
#if MONO // copy behavior from reference source
            if (info == null)
                throw new ArgumentNullException("info");

            // Must use V1 field names here, since V1 didn't implement
            // ISerializable.
            FullPath = Path.GetFullPathInternal(info.GetString("FullPath"));
            OriginalPath = info.GetString("OriginalPath");
            _name = info.GetString("Name");
        }
Exemple #18
0
        internal static String InternalCopy(String sourceFileName, String destFileName, bool overwrite)
        {
            if (sourceFileName == null || destFileName == null)
            {
                throw new ArgumentNullException((sourceFileName == null ? "sourceFileName" : "destFileName"), Environment.GetResourceString("ArgumentNull_FileName"));
            }
            if (sourceFileName.Length == 0 || destFileName.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), (sourceFileName.Length == 0 ? "sourceFileName" : "destFileName"));
            }

            String fullSourceFileName = Path.GetFullPathInternal(sourceFileName);

            new FileIOPermission(FileIOPermissionAccess.Read, new String[] { fullSourceFileName }, false, false).Demand();
            String fullDestFileName = Path.GetFullPathInternal(destFileName);

            new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullDestFileName }, false, false).Demand();

            bool r = Win32Native.CopyFile(fullSourceFileName, fullDestFileName, !overwrite);

            if (!r)
            {
                // Save Win32 error because subsequent checks will overwrite this HRESULT.
                int    errorCode = Marshal.GetLastWin32Error();
                String fileName  = destFileName;

                if (errorCode != Win32Native.ERROR_FILE_EXISTS)
                {
                    // For a number of error codes (sharing violation, path
                    // not found, etc) we don't know if the problem was with
                    // the source or dest file.  Try reading the source file.
                    using (SafeFileHandle handle = Win32Native.UnsafeCreateFile(fullSourceFileName, FileStream.GENERIC_READ, FileShare.Read, null, FileMode.Open, 0, IntPtr.Zero)) {
                        if (handle.IsInvalid)
                        {
                            fileName = sourceFileName;
                        }
                    }

                    if (errorCode == Win32Native.ERROR_ACCESS_DENIED)
                    {
                        if (Directory.InternalExists(fullDestFileName))
                        {
                            throw new IOException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_FileIsDirectory_Name"), destFileName), Win32Native.ERROR_ACCESS_DENIED, fullDestFileName);
                        }
                    }
                }

                __Error.WinIOError(errorCode, fileName);
            }

            return(fullDestFileName);
        }
        //| <include file='doc\DirectoryInfo.uex' path='docs/doc[@for="DirectoryInfo.MoveTo"]/*' />
        public void MoveTo(String destDirName)
        {
            if (destDirName == null)
            {
                throw new ArgumentNullException("destDirName");
            }
            if (destDirName.Length == 0)
            {
                throw new ArgumentException("Argument_EmptyFileName", "destDirName");
            }

            String fullDestDirName = Path.GetFullPathInternal(destDirName);

            if (!fullDestDirName.EndsWith('\\'))
            {
                fullDestDirName = fullDestDirName + "\\";
            }

            String fullSourcePath;

            if (FullPath.EndsWith('\\'))
            {
                fullSourcePath = FullPath;
            }
            else
            {
                fullSourcePath = FullPath + "\\";
            }

            if (CompareInfo.Compare(fullSourcePath, fullDestDirName, CompareOptions.IgnoreCase) == 0)
            {
                throw new IOException("IO.IO_SourceDestMustBeDifferent");
            }

            String sourceRoot      = Path.GetPathRoot(fullSourcePath);
            String destinationRoot = Path.GetPathRoot(fullDestDirName);

            if (CompareInfo.Compare(sourceRoot, destinationRoot, CompareOptions.IgnoreCase) != 0)
            {
                throw new IOException("IO.IO_SourceDestMustHaveSameRoot");
            }

            if (!Native.MoveFile(FullPath, destDirName))
            {
                __Error.WinIOError(Native.ERROR_PATH_NOT_FOUND, OriginalPath);
            }
            FullPath     = fullDestDirName;
            OriginalPath = destDirName;

            // Flush any cached information about the directory.
            _dataInitialised = -1;
        }
Exemple #20
0
        public static string GetTempPath()
        {
            new EnvironmentPermission(PermissionState.Unrestricted).Demand();
            StringBuilder buffer   = new StringBuilder(260);
            uint          tempPath = Win32Native.GetTempPath(260, buffer);
            string        path     = ((object)buffer).ToString();

            if ((int)tempPath == 0)
            {
                __Error.WinIOError();
            }
            return(Path.GetFullPathInternal(path));
        }
Exemple #21
0
        /// <include file='doc\DirectoryInfo.uex' path='docs/doc[@for="DirectoryInfo.CreateSubdirectory"]/*' />
        public DirectoryInfo CreateSubdirectory(String path) {
            if (path==null)
                throw new ArgumentNullException("path");
			
            String newDirs = Path.InternalCombine(FullPath, path);
			String fullPath = Path.GetFullPathInternal(newDirs);

			if (0!=String.Compare(FullPath,0,fullPath,0, FullPath.Length,true, CultureInfo.InvariantCulture))
				throw new ArgumentException(String.Format(Environment.GetResourceString("Argument_InvalidSubPath"),path,OriginalPath));
			
            Directory.InternalCreateDirectory(fullPath,path);
			return new DirectoryInfo(fullPath, false);
        }
Exemple #22
0
        public static string GetTempPath()
        {
            new EnvironmentPermission(PermissionState.Unrestricted).Demand();
            StringBuilder buffer  = new StringBuilder(260);
            int           num     = (int)Win32Native.GetTempPath(260, buffer);
            string        @string = buffer.ToString();

            if (num == 0)
            {
                __Error.WinIOError();
            }
            return(Path.GetFullPathInternal(@string));
        }
Exemple #23
0
        public static string GetDirectoryRoot(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            string fullPathInternal = Path.GetFullPathInternal(path);
            string fullPath         = fullPathInternal.Substring(0, Path.GetRootLength(fullPathInternal));
            string demandDir        = GetDemandDir(fullPath, true);

            new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new string[] { demandDir }, false, false).Demand();
            return(fullPath);
        }
        //| <include file='doc\DirectoryInfo.uex' path='docs/doc[@for="DirectoryInfo.DirectoryInfo"]/*' />
        public DirectoryInfo(String path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            OriginalPath = path;

            // Must fully qualify the path for the security check
            String fullPath = Path.GetFullPathInternal(path);

            FullPath = fullPath;
        }
        public FileInfo(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            base.OriginalPath = fileName;
            string fullPathInternal = Path.GetFullPathInternal(fileName);

            new FileIOPermission(FileIOPermissionAccess.Read, new string[] { fullPathInternal }, false, false).Demand();
            this._name       = Path.GetFileName(fileName);
            base.FullPath    = fullPathInternal;
            base.DisplayPath = this.GetDisplayPath(fileName);
        }
Exemple #26
0
        public FileInfo(String fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            OriginalPath = fileName;
            // Must fully qualify the path for the security check
            String fullPath = Path.GetFullPathInternal(fileName);

            _name    = Path.GetFileName(fileName);
            FullPath = fullPath;
        }
Exemple #27
0
        public static FileAttributes GetAttributes(string path)
        {
            string fullPathInternal = Path.GetFullPathInternal(path);

            new FileIOPermission(FileIOPermissionAccess.Read, new string[] { fullPathInternal }, false, false).Demand();
            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            int errorCode = FillAttributeInfo(fullPathInternal, ref data, false, true);

            if (errorCode != 0)
            {
                __Error.WinIOError(errorCode, fullPathInternal);
            }
            return((FileAttributes)data.fileAttributes);
        }
Exemple #28
0
        internal static String InternalCopy(String sourceFileName, String destFileName, bool overwrite, bool checkHost)
        {
            String fullSourceFileName = Path.GetFullPathInternal(sourceFileName);
            String fullDestFileName   = Path.GetFullPathInternal(destFileName);

            MonoIOError error;

            if (!MonoIO.CopyFile(fullSourceFileName, fullDestFileName, overwrite, out error))
            {
                string p = Locale.GetText("{0}\" or \"{1}", sourceFileName, destFileName);
                throw MonoIO.GetException(p, error);
            }

            return(fullDestFileName);
        }
Exemple #29
0
        protected FileSystemInfo(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            // Must use V1 field names here, since V1 didn't implement
            // ISerializable.
            FullPath     = Path.GetFullPathInternal(info.GetString("FullPath"));
            OriginalPath = info.GetString("OriginalPath");

            // Lazily initialize the file attributes.
            _dataInitialised = -1;
        }
Exemple #30
0
        public static void SetAttributes(string path, FileAttributes fileAttributes)
        {
            string fullPathInternal = Path.GetFullPathInternal(path);

            new FileIOPermission(FileIOPermissionAccess.Write, new string[] { fullPathInternal }, false, false).Demand();
            if (!Win32Native.SetFileAttributes(fullPathInternal, (int)fileAttributes))
            {
                int errorCode = Marshal.GetLastWin32Error();
                if (errorCode == 0x57)
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileAttrs"));
                }
                __Error.WinIOError(errorCode, fullPathInternal);
            }
        }