示例#1
0
        /// <summary>
        /// Gets the information about a file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="fileHandle">The file handle.</param>
        /// <returns>The file characteristics, if the file information was retrieved successfully, otherwise null.</returns>
        public override FileCharacteristics GetFileCharacteristics(string fileName, IntPtr fileHandle)
        {
            Win32FileNativeMethods.BY_HANDLE_FILE_INFORMATION fileInfo;
            if (Win32FileNativeMethods.GetFileInformationByHandle(fileHandle, out fileInfo))
            {
                return(new FileCharacteristics(DateTime.FromFileTimeUtc(fileInfo.ftCreationTime), fileInfo.nFileSizeLow + (((long)fileInfo.nFileSizeHigh) << 32)));
            }

            return(null);
        }
示例#2
0
 /// <summary>
 /// Gets the information about a file.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="fileStream">The file stream.</param>
 /// <returns>The file characteristics, if the file information was retrieved successfully, otherwise null.</returns>
 public override FileCharacteristics GetFileCharacteristics(string fileName, FileStream fileStream)
 {
     if (fileStream != null)
     {
         Win32FileNativeMethods.BY_HANDLE_FILE_INFORMATION fileInfo;
         if (Win32FileNativeMethods.GetFileInformationByHandle(fileStream.SafeFileHandle.DangerousGetHandle(), out fileInfo))
         {
             return(new FileCharacteristics(DateTime.FromFileTimeUtc(fileInfo.ftCreationTime), DateTime.FromFileTimeUtc(fileInfo.ftLastWriteTime), fileInfo.nFileSizeLow + (((long)fileInfo.nFileSizeHigh) << 32)));
         }
     }
     return(null);
 }
示例#3
0
        /// <summary>
        /// Gets the information about a file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="fileHandle">The file handle.</param>
        /// <param name="lastWriteTime">The last write time of the file in UTC.</param>
        /// <param name="fileLength">Length of the file.</param>
        /// <returns>
        /// A value of <c>true</c> if file information was retrieved successfully, <c>false</c> otherwise.
        /// </returns>
        public override bool GetFileInfo(string fileName, IntPtr fileHandle, out DateTime lastWriteTime, out long fileLength)
        {
            Win32FileNativeMethods.BY_HANDLE_FILE_INFORMATION fi;

            if (Win32FileNativeMethods.GetFileInformationByHandle(fileHandle, out fi))
            {
                lastWriteTime = DateTime.FromFileTimeUtc(fi.ftLastWriteTime);
                fileLength    = fi.nFileSizeLow + (((long)fi.nFileSizeHigh) << 32);
                return(true);
            }
            else
            {
                lastWriteTime = DateTime.MinValue;
                fileLength    = -1;
                return(false);
            }
        }