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
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?
Re: SetCreationTime on a opened file
Thanks for replying.
That is what I ended up doing, but I find it extremely inconvenient.