safely lock a file then move? windows

Posted by acidzombie24 on Stack Overflow See other posts from Stack Overflow or by acidzombie24
Published on 2010-03-11T04:16:14Z Indexed on 2010/03/11 4:39 UTC
Read the original article Hit count: 563

Filed under:
|
|
|
|

I have a file and need to ensure it exist before inserting a row into the db. After i insert i need to use the PK as part of the filename and move it into another location.

How do i check if it exist then lock it so it cant be deleted until i can insert into the db then proceed to move the file without it being deleted upon releasing the lock?

also the file may be in use. I am thinking of copying the file into a safe location then moving that file away. In this case i need to copy a file that is being used for reading. How can i do the above steps safely?

Using .NET

© Stack Overflow or respective owner

Related posts about Windows

Related posts about file