Exemple #1
0
        public static void SetAttributes(String path, FileAttributes fileAttributes)
        {
            String fullPath = Path.GetFullPath(path);
            bool   r        = Win32Native.SetFileAttributes(fullPath, (int)fileAttributes);

            if (!r)
            {
                int hr = Marshal.GetLastWin32Error();
                if (hr == ERROR_INVALID_PARAMETER)
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileAttrs"));
                }
                __Error.WinIOError(hr, fullPath);
            }
        }
Exemple #2
0
        /// <include file='doc\File.uex' path='docs/doc[@for="File.SetAttributes"]/*' />
        public static void SetAttributes(String path, FileAttributes fileAttributes)
        {
            String fullPath = Path.GetFullPathInternal(path);

            new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullPath }, false, false).Demand();
            bool r = Win32Native.SetFileAttributes(fullPath, (int)fileAttributes);

            if (!r)
            {
                int hr = Marshal.GetLastWin32Error();
                if (hr == ERROR_INVALID_PARAMETER || hr == ERROR_ACCESS_DENIED) // Hack for Win98 to which returns Access denied sometimes
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileAttrs"));
                }
                __Error.WinIOError(hr, path);
            }
        }