0

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?

2
  • 4
    A voice in my head tells me that you should not be doing this. Some description of your scenario will help. Commented Dec 29, 2010 at 6:24
  • I don't suppose that this is a file you created yourself, using something like File.Create? Commented Dec 29, 2010 at 7:18

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is correct. And even if you don't mind, that other process most certainly does. So don't do this.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.