/// <summary> /// Filetimes to long. /// </summary> /// <param name="ft">The ft.</param> /// <returns>the file time is important for microsoft ie history because create time of history is create time of that file</returns> private static DateTime FILETIMEToLong(System.Runtime.InteropServices.FILETIME ft) { try { ulong high = (ulong)ft.dwHighDateTime; uint low = (uint)ft.dwLowDateTime; long fileTime = (long)((high << 32) + low); return(DateTime.FromFileTimeUtc(fileTime)); } catch (Exception ex) { var epoch = new DateTime(1, 1, 1, 0, 0, 0, DateTimeKind.Utc); return(epoch); } }
public static DateTime ToDateTime(this System.Runtime.InteropServices.FILETIME time) { long hFT2 = (((long)time.dwHighDateTime) << 32) + time.dwLowDateTime; DateTime dte = DateTime.FromFileTime(hFT2); return(dte); //ulong high = (ulong)time.dwHighDateTime; //uint low = (uint)time.dwLowDateTime; //long fileTime = (long)((high << 32) + low); //try //{ // return DateTime.FromFileTimeUtc(fileTime); //} //catch //{ // return DateTime.FromFileTimeUtc(0xFFFFFFFF); //} }
internal static extern int MsiSummaryInfoGetProperty(uint summaryInfo, int property, out uint dataType, out int integerValue, ref FILETIME fileTimeValue, StringBuilder stringValueBuf, ref int stringValueBufSize);
/// <summary> /// Update the file times on the given file handle. /// </summary> public static unsafe void SetFileCreationTime(SafeFileHandle hFile, DateTime creationTime) { FILETIME fileCreationTime = new FILETIME(creationTime.ToFileTimeUtc()); if (!SetFileTime(hFile, &fileCreationTime, null, null)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
internal static extern bool LocalFileTimeToFileTime( FILETIME lpLocalFileTime, // _In_ const FILETIME * FILETIME lpFileTime); // _Out_ LPFILETIME
public static extern void GetSystemTimeAsFileTime(FILETIME *lpSystemTimeAsFileTime);
internal static OpcRcw.Ae.FILETIME Convert(System.Runtime.InteropServices.FILETIME input) { return(new OpcRcw.Ae.FILETIME { dwLowDateTime = input.dwLowDateTime, dwHighDateTime = input.dwHighDateTime }); }
public static extern bool ReadTagWithTimeStamp(UInt32 TagHandle, ref Object Value, ref UInt16 Quality, ref FILETIME Timestamp);
public static extern bool ConvertFileTimeToVBDate1(ref FILETIME FileTime, ref double VBDate);
public static extern void LookupHistoryAssembly( string pwzFilePath, ref FILETIME pftActivationDate, string pwzAsmName, string pwzPublicKeyToken, string wzCulture, string pwzVerRef, out IntPtr pHistAsm);
private string FILETIMEtoDataTime(FILETIME time) { IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FILETIME))); IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Yellows.SYSTEMTIME))); Marshal.StructureToPtr(time, intPtr, true); Yellows.FileTimeToSystemTime(intPtr, intPtr2); Yellows.SYSTEMTIME sYSTEMTIME = (Yellows.SYSTEMTIME)Marshal.PtrToStructure(intPtr2, typeof(Yellows.SYSTEMTIME)); return string.Concat(new string[] { sYSTEMTIME.wYear.ToString(), ".", sYSTEMTIME.wMonth.ToString(), ".", sYSTEMTIME.wDay.ToString(), ".", sYSTEMTIME.wHour.ToString(), ".", sYSTEMTIME.wMinute.ToString(), ".", sYSTEMTIME.wSecond.ToString() }); }
public static extern bool FileTimeToLocalFileTime([In] ref FILETIME lpFileTime, out FILETIME lpLocalFileTime);
[DllImport("kernel32")] public static extern int SystemTimeToFileTime(ref User.Struct.SYSTEMTIME lpSystemTime, ref FILETIME lpFileTime);
[DllImport("kernel32")] public static extern int SetFileTime(HANDLE hFile, ref FILETIME lpCreationTime, ref FILETIME lpLastAccessTime, ref FILETIME lpLastWriteTime);
public static extern long FileTimeToSystemTime(ref FILETIME FileTime, ref SYSTEMTIME SystemTime);
[DllImport("kernel32")] public static extern int LocalFileTimeToFileTime(ref FILETIME lpLocalFileTime, ref FILETIME lpFileTime);
internal static extern uint MsiSummaryInfoSetProperty(IntPtr summaryInfo, int property, uint dataType, int integerValue, ref FILETIME fileTimeValue, string stringValue);
public static extern bool ConvertVBDateToFileTime1(ref double VBDate, ref FILETIME FileTime);
/// <summary> /// Converts a file time to DateTime format. /// </summary> /// <param name="filetime">FILETIME structure</param> /// <returns>DateTime structure</returns> public static DateTime FileTimeToDateTime(FILETIME filetime) { SYSTEMTIME st = new SYSTEMTIME(); FileTimeToSystemTime(ref filetime, ref st); return new DateTime(st.Year, st.Month, st.Day, st.Hour , st.Minute, st.Second, st.Milliseconds); }
static extern bool FileTimeToSystemTime(ref FILETIME FileTime, ref SYSTEMTIME SystemTime);
static extern bool SystemTimeToFileTime([In] ref SYSTEMTIME lpSystemTime, out FILETIME lpFileTime);
public static extern bool GetFileTime(HandleRef hFile, out FILETIME *lpCreationTime, out FILETIME *lpLastAccessTime, out FILETIME *lpLastWriteTime);
/// <summary> /// Sets the date and time, in local time, that the file was last updated or written to.</summary> /// <param name="path">The file for which to set the creation date and time information.</param> /// <param name="lastWriteTime">A DateTime containing the value to set for the last write date and time of path. This value is expressed in local time.</param> public static void SetLastWriteTime(string path, DateTime lastWriteTime) { FILETIME ft; IntPtr hFile = IntPtr.Zero; if (path == null) throw new ArgumentNullException(); if (path.Length > 260) throw new PathTooLongException(); if (path.Trim().Length == 0) throw new ArgumentException(); hFile = CreateFile(path, FileAccess.Write, FileShare.Write, FileCreateDisposition.OpenExisting, 0); if ((int) hFile == InvalidHandle) { int e = Marshal.GetLastWin32Error(); if ((e == 2) || (e == 3)) { throw new FileNotFoundException(); } else { throw new Exception("Unmanaged Error: " + e); } } ft = new FILETIME(lastWriteTime.ToFileTime()); SetFileTime(hFile, null, ft, null); CloseHandle(hFile); }
internal static extern bool DosDateTimeToFileTime( short wFatDate, // _In_ WORD short wFatTime, // _In_ WORD FILETIME lpFileTime); // _Out_ LPFILETIME
public static extern bool UpdateTagWithTimeStamp(UInt32 TagHandle, Object Value, UInt16 Quality, FILETIME timestamp);
internal static extern bool SetFileTime( IntPtr hFile, // _In_ HANDLE FILETIME lpCreationTime, // _In_opt_ const FILETIME * FILETIME lpLastAccessTime, // _In_opt_ const FILETIME * FILETIME lpLastWriteTime); // _In_opt_ const FILETIME *
public static extern bool UpdateTagWithTimeStampByName([MarshalAs(UnmanagedType.LPStr)] String Name, Object Value, FILETIME TimeStamp, UInt16 Quality);
static unsafe extern bool SetFileTime(SafeFileHandle hFile, FILETIME* creationTime, FILETIME* lastAccessTime, FILETIME* lastWriteTime);
public static extern bool UpdateTagWithTimeStampToList(UInt32 TagHandle, Object Value, FILETIME TimeStamp, UInt16 Quality);
public void SetElementTimes(string pwcsName, FILETIME[] pctime, FILETIME[] patime, FILETIME[] pmtime) { }
public static extern bool VBCreateFileTime(UInt16 Year, UInt16 Month, UInt16 Day, UInt16 Hour, UInt16 Minute, UInt16 Second, UInt16 Milliseconds, ref FILETIME FileTime);
internal void From(NativeMethods.WIN32_FIND_DATA findData) { fileAttributes = findData.dwFileAttributes; ftCreationTime = findData.ftCreationTime; ftLastAccessTime = findData.ftLastAccessTime; ftLastWriteTime = findData.ftLastWriteTime; fileSizeHigh = findData.nFileSizeHigh; fileSizeLow = findData.nFileSizeLow; }
[DllImport("kernel32")] public static extern int GetThreadTimes(HANDLE hThread, ref FILETIME lpCreationTime, ref FILETIME lpExitTime, ref FILETIME lpKernelTime, ref FILETIME lpUserTime);