private void initializePropertyFromFileAttributes() { // Get the file attributes by the native function. NativeMethods.WIN32_FILE_ATTRIBUTE_DATA fileAttributeData; if (!NativeMethods.GetFileAttributesExW(UncFilePath, NativeMethods.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out fileAttributeData)) { int err = Marshal.GetLastWin32Error(); string message = string.Format(@"Failed GetFileAttributesExW function with {0}. The file path is ""{1}""", err, UncFilePath); throw new Win32Exception(err, message); } // Initialize the properties. FileSize = NativeMethodHelper.NativeUInt32HighLowToUInt64(fileAttributeData.FileSizeHigh, fileAttributeData.FileSizeLow); CreationTimeUtc = NativeMethodHelper.NativeFileTimeToDateTimeUtc(fileAttributeData.CreationTime); LastAccessTimeUtc = NativeMethodHelper.NativeFileTimeToDateTimeUtc(fileAttributeData.LastAccessTime); LastWriteTimeUtc = NativeMethodHelper.NativeFileTimeToDateTimeUtc(fileAttributeData.LastWriteTime); }
private string extractFileVersion(byte[] fileVerInfoData) { // Read the file version from the version information resource. IntPtr value; uint valueLength; if (NativeMethods.VerQueryValueW(fileVerInfoData, @"\", out value, out valueLength)) { NativeMethods.VS_FIXEDFILEINFO fixedFileInfo; fixedFileInfo = (NativeMethods.VS_FIXEDFILEINFO)Marshal.PtrToStructure(value, typeof(NativeMethods.VS_FIXEDFILEINFO)); return string.Format(@"{0}.{1}.{2}.{3}", NativeMethodHelper.GetHighWord(fixedFileInfo.FileVersionMS), NativeMethodHelper.GetLowWord(fixedFileInfo.FileVersionMS), NativeMethodHelper.GetHighWord(fixedFileInfo.FileVersionLS), NativeMethodHelper.GetLowWord(fixedFileInfo.FileVersionLS)); } // Try with language and code page if above failed. NativeMethods.LangAndCodePage[] langsAndCodePages = getLanguageCodePagePairs(fileVerInfoData); if (langsAndCodePages == null) return string.Empty; // Get file version information value. return getFileVersionInfoValue(fileVerInfoData, langsAndCodePages, @"FileVersion"); }