コード例 #1
0
        public static FileIdentityInformation GetVolumeIdAndUniqueIdForFolder(string fullPathWithFolderName)
        {
            var directoryHandleInformation = new FileSystemInteractor.BY_HANDLE_FILE_INFORMATION();

            try
            {
                // OPEN_EXISTING (FileMode.Open) is specified as we know the folder exists when passed into this method;
                // however, if it doesn't, a FileNotFoundException is thrown
                var createdFolder =
                    FileSystemInteractor.CreateFile(
                        fullPathWithFolderName,
                        FileAccess.Read,
                        FileShare.Read,
                        IntPtr.Zero,
                        FileMode.Open,
                        Kernel32.FILE_FLAG_BACKUP_SEMANTICS,
                        IntPtr.Zero
                        );

                FileSystemInteractor.GetFileInformationByHandle(createdFolder.DangerousGetHandle(), out directoryHandleInformation);


                return
                    (new FileIdentityInformation
                     (
                         directoryHandleInformation.VolumeSerialNumber,
                         directoryHandleInformation.FileIndexHigh,
                         directoryHandleInformation.FileIndexLow
                     ));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }