ratty
ratty

Reputation: 13434

How can I write to a file that is in use by another process in C#?

How can I write to a file which is used by another process in C#?

I am able to read the file using FileShare.ReadWrite, but it only works for FileAccess.Read. Does anyone have a solution?

Upvotes: 0

Views: 145

Answers (2)

RobbanP
RobbanP

Reputation: 143

You should read the file contents to a separate Stream and then the file is released.

Upvotes: 0

Jamie
Jamie

Reputation: 3931

If the other process has write-locked the file, then there's not much you can do, unless you don't mind closing the other process's handle or killing it.

Upvotes: 4

Related Questions