public static void Encrypt(String path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } Contract.EndContractBlock(); String fullPath = Path.GetFullPath(path); FileIOPermission.QuickDemand(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, fullPath, false, false); bool r = Win32Native.EncryptFile(fullPath); if (!r) { int errorCode = Marshal.GetLastWin32Error(); if (errorCode == Win32Native.ERROR_ACCESS_DENIED) { // Check to see if the file system is not NTFS. If so, // throw a different exception. DriveInfo di = new DriveInfo(Path.GetPathRoot(fullPath)); if (!String.Equals("NTFS", di.DriveFormat)) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_EncryptionNeedsNTFS")); } } __Error.WinIOError(errorCode, fullPath); } }