• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

How Can I Append a file in use

I need to a text to a file that is open.

Dim fs As New FileStream(DestEFB, FileMode.Append, FileAccess.Write, FileShare.Write)
                Dim sw As New StreamWriter("Destattion_Open_File.txt", True)
                Dim NextLine As String = vbCrLf & "This is the appended text."

But I get the file in use error
Anyone now a way around this.
  • 2
1 Solution
It is not a programming problem. The operating system will not allow this to prevent loss of data. If user one makes a change and then your program makes a change, the first save will be overwritten by the second.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Right...you need to pause for a second or two after "fs.Close()" and allow the operating system to finish with the file and release the file handles completely before attempting to append to it...
buzzcarterAuthor Commented:
Thanks Idle Mind but the exception fire @ Dim fs As New FileStream(DestEFB, FileMode.Append, FileAccess.Write, FileShare.Write)

I am look for away around this filesystem protection.
buzzcarterAuthor Commented:
This is not possible. One possible solution is to be the first application to create the file.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now