/// <summary> /// Sets the specified <see cref="FileAttributes" /> of the entry on the specified path. /// </summary> /// <param name="pathInfo">The path to the entry.</param> /// <param name="attributes">A bitwise combination of the enumeration values.</param> /// <exception cref="Win32Exception">Unmatched Exception</exception> public static void SetAttributes(PathInfo pathInfo, FileAttributes attributes) { if (Win32SafeNativeMethods.SetFileAttributes(pathInfo.FullNameUnc, (uint)attributes)) { return; } int win32Error = Marshal.GetLastWin32Error(); NativeExceptionMapping(pathInfo.FullName, win32Error); }
/// <summary> /// Sets the specified <see cref="FileAttributes"/> of the entry on the specified path. /// </summary> /// <param name="path">The path to the entry.</param> /// <param name="attributes">A bitwise combination of the enumeration values.</param> /// <exception cref="Win32Exception">Unmatched Exception</exception> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static FileAttributes SetAttributes(String path, FileAttributes attributes) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); if (!Win32SafeNativeMethods.SetFileAttributes(path, ( uint )attributes)) { var win32Error = Marshal.GetLastWin32Error(); Win32ErrorCodes.NativeExceptionMapping(path, win32Error); } return(attributes); }