Skip to content

Windows: open file for writing (lock file)

July 19, 2017

Sometimes you need to lock file and investigate how an application under the test will be working.

There are few steps to implement it:

  1. Open PowerShell console
  2. Write the following code:
    $file=[System.io.File]::Open('full/path/to/your/file', 'append', 'Write', 'None')
    
  3. Your test steps…
  4. Don’t forget to close the file after testing by
    $file.Close()
    

P.S.: It’s possible that it’ll be the error in your application log:

Exception calling "Open" with "4" argument(s): "The process cannot access the file 'full/path/to/your/file'' because it is being used by another process."
Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: