© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
12 replies
Diesel Geezer

Access file that is being used by another application using FileStream

public void WriteToBinaryFile(string filePath, ListView listview)
        {
            FileStream fsWrite = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite); // I GET AN EXCEPTION HERE
            BinaryFormatter binfmt = new BinaryFormatter();
            InvokeIfRequired(listview,()=> { binfmt.Serialize(fsWrite, new ArrayList(listview.Items)); });
            
            fsWrite.Close();
        }
public void WriteToBinaryFile(string filePath, ListView listview)
        {
            FileStream fsWrite = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite); // I GET AN EXCEPTION HERE
            BinaryFormatter binfmt = new BinaryFormatter();
            InvokeIfRequired(listview,()=> { binfmt.Serialize(fsWrite, new ArrayList(listview.Items)); });
            
            fsWrite.Close();
        }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Cannot access file because it's being used by another process
C#CC# / help
3y ago
How to overwrite a file that is used by another process?
C#CC# / help
12mo ago
❔ "cant open file due to it being used by another process"
C#CC# / help
3y ago