Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:24:17+00:00 2026-06-15T11:24:17+00:00

I am making an encryption program that also functions as a notepad (CryptoMatic). There

  • 0

I am making an encryption program that also functions as a notepad (CryptoMatic). There is a Open function with the following code:

    Dim r As New StreamReader(filename)
    Dim text As String = r.ReadToEnd
    txtFileContents.text = text

    r.Dispose()
    r.Close()

Now there is the save and save as button
the save button checks if the file had been saved previously or not. If yes then I am trying to write to that file with the following code:

    Dim myFileStream As New System.IO.FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.None)
    myFileStream.Lock(0, 100)

    Dim myWriter As New System.IO.StreamWriter(myFileStream)
    myWriter.WriteLine(text)

    myWriter.Flush()
    myWriter.Close()
    myFileStream.Close()

    myFileStream.Unlock(0, 100)

Now when i press the save button it gives the following error:

    The process cannot access the file 'C:\Users\VisualTech\Documents\Visual Studio            2010\Projects\CryptoMatic Update\CryptoMatic Update\bin\Debug\text.txt' because it is being    used by another process.

and the application stops, can anyone please help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:24:19+00:00Added an answer on June 15, 2026 at 11:24 am

    I have tried your code above and have noticed two things:

    • You don’t need a myFileStream.Lock call because you already open it
      with FileShare.None
    • You can’t call myFileStream.Unlock(0, 100) after the call to
      myFileStream.Close()

    So I have rewritten your code in this way.

    Sub Main
        Dim text = "This is a text to write in the stream"
        Using myFileStream As New System.IO.FileStream("D:\temp\testlock.txt", FileMode.Append, FileAccess.Write, FileShare.None)
            Using myWriter As New System.IO.StreamWriter(myFileStream)
                myWriter.WriteLine(text)
            End Using
        End Using
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making UML sequence diagram in VS 2010RC I've observed that there is no activation
Making websites that appear correctly in IE is a big problem. Is there any
I'm making a simple program that takes text entered in a text box, and
i am making a program to implement xor encryption,while playing around with my program
Making a new site but something is happening to it in IE8. The social
Making a new site but something is happening to it in IE. I've purchased
Making an adobe flex ui in which data that is calculated must use proprietary
I'm making a simple custom encrypting in C#.NET, the encryption passes succesfully, but the
Is there a norm for AJAX security? When making an XMLHttpRequest, if querying an
I have a quick little app that steps through the possible symmetric encryption methods.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.