You can use FileStream.Lock and FileStream.UnLock for locking the file.
Check out this article on MSDN for Lock :
http://msdn.microsoft.com/en-us/library/system.io.filestream.lock(VS.71).aspx
Check out this article on MSDN for UNLock :
http://msdn.microsoft.com/en-us/library/system.io.filestream.unlock(VS.71).aspx
Hope this helps!!