-
August 21st, 2011, 03:27 PM
#1
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
-
August 23rd, 2011, 01:31 AM
#2
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?
-
August 24th, 2011, 08:21 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|