SetCreationTime on a opened file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: SetCreationTime on a opened file

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    SetCreationTime on a opened file

    Hi all,

    I need to set Creation Time on a newly created file before I close this file. I use FileStream to create the files.

    In C++/Win32 programming, I can say

    HANDLE hFile = CreateFile(...);
    WriteFile( hFile, ...);
    SetFileTime( hFile, ....);
    CloseHandle( hFile );

    However, in .NET, I can't seem to call File.SetCreationTime on a file until I close the FileStream. I get the error "The process cannot access the file ... because it is being used by another process."

    Unfortunately I can't close the file and then set the Creation Time because another process (a service running in the background) may snatch the file from the folder right after it's closed but before I have the chance to change its Creation Time.

    Any way to do it in .NET?

    Thanks in advance

    DC Dweller

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,295

    Re: SetCreationTime on a opened file

    Can you create the file in a temporary directory, set the file creation time and then call File.Move to move the file into the directory where the service can pick it up?

  3. #3
    Join Date
    Aug 2011
    Posts
    2

    Re: SetCreationTime on a opened file

    Thanks for replying.

    That is what I ended up doing, but I find it extremely inconvenient.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center