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

  • SEARCH
  • Home
  • 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 9108671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:51:45+00:00 2026-06-17T02:51:45+00:00

Possible Duplicate: File being used by another process after using File.Create() I have a

  • 0

Possible Duplicate:
File being used by another process after using File.Create()

I have a method that will append text to a file. Before I append the text I check if the file exists. If it does not exist I create it then carry on as shown below.

if(!File.Exists(_someFile))
    File.Create(_someFile);

using (StreamWriter file = File.AppendText(_someFile))
{          
    file.WriteLine("some text");
}

If the file exists there is no problem. The file will be updated. If the file does not exist and it gets created an IO exception is thrown on the line with the ‘using’, stating that another process is using the file. I tried to use process explorer to find out what is using the file and the result is “non existent process”.
Does anyone know what is happening and how to solve this problem?

EDIT: Problem solved

I could not find a question about my problem on this site when I first searched. As soon as I posted my question I saw the exact problem being address in the ‘related questions’ on the right.
Link to the solution: File being used by another process after using File.Create()
Sorry for posting a duplicate.
My problem is solved.

  • 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-17T02:51:46+00:00Added an answer on June 17, 2026 at 2:51 am

    This happens because File.Create(_someFile); opens the file stream which must be closed before you can use the new created file.
    Try this:

    if(!File.Exists(_someFile))
    {
        using (var stream = File.Create(_someFile))
    }
    using (StreamWriter file = File.AppendText(_someFile))
    {          
        file.WriteLine("some text");
    }
    

    But actually you don’t need to check and create the file first. StreamWriter will create the file if it does’t exist or append the text to it if it does exist.

    using (StreamWriter sw = new StreamWriter(_someFile, true))
    {
        file.WriteLine("some text");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: The file is being used by another process, I must close it?
Possible Duplicate: Mercurial: copying ONE file and its history to another repository I have
Possible Duplicate: How can I delete a file that is in use by another
Possible Duplicate: Limit file format when using <input type=file>? I need to use the
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Possible Duplicate: Create Excel file in Java How to save output in excel format
Possible Duplicate: Problem executing bash file I have created a bash file script and
Possible Duplicate: PHP create a file without fopen I want to create a file
Possible Duplicate: How to check file types of uploaded files in PHP? I have
Possible Duplicate: Loop code for each file in a directory I assumed that I

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.