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 8941119
In Process

The Archive Base Latest Questions

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

Possible Duplicate: Open file ReadOnly In my application I am writing some information to

  • 0

Possible Duplicate:
Open file ReadOnly

In my application I am writing some information to Log.txt using Debug.WriteLine(), and I want to provide a form which will show the contents of Log.txt.

But when I try to open the file Log.txt I am getting an exception:

The process cannot access the file ‘F:\Rajeev\10-11-2012\Temp\Temp\bin\Debug\Log.txt’ because it is being used by another process.

How do I overcome this problem?

And here another issue is, I am able to open the same file using Notepad. Then why can’t I open the same file using my application?

The following is the code I am using for specifying the log file:

TextWriterTraceListener tr = new TextWriterTraceListener(System.IO.File.CreateText("Log.txt"));
Debug.Listeners.Add(tr);
Debug.AutoFlush = true;

The following is the code I am using for writing to the log file:

Debug.WriteLine("ERROR: Invalid Username " + s);

The following is the code I am using for opening a log file (which is already opened by “Debug”) to show in Log Viewer (a “Form” in my application):

File.Open(LogFilePath, FileMode.Open, FileAccess.Read,FileShare.Read);
  • 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:13:39+00:00Added an answer on June 15, 2026 at 11:13 am

    This is determined by the permissions the file is opened with. If a program opens the file in any type of exclusive mode, then other programs will have limited or no access.

    So you can make sure you don’t try to open the file exclusively (you didn’t show your code). However, if you don’t have the source code for the other program, then you can only hope that that program doesn’t open the file exclusively. Otherwise, I don’t see what you could do about it except terminate the other program.

    EDIT

    The following code:

    File.Open(LogFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
    

    Says that other files can also read the file that is open, but I believe they can’t write to it. So if the other program was writing to the file, that would not be allowed. You could try FileShare.ReadWrite instead but I’m still not seeing where you’ve indicated if you have source to the other program. Did I just miss it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: iPhone Mobile Safari File System Access I want to open a locally
Possible Duplicate: Putting a .txt file into a DataGridView When I click an open
Possible Duplicate: RegEx match open tags except XHTML self-contained tags I have a file
Possible Duplicate: RegEx match open tags except XHTML self-contained tags i want to grap
Possible duplicate What is the best open source example of a lightweight Windows Application?
Possible Duplicate: Open file from complete path under cursor in Vim Let's say I
Possible Duplicate: Access to file download dialog in Firefox I'm using selenium and firefox
Possible Duplicate: PHP code can insert image to excel file and open it correctly
Possible Duplicate: Reading a .doc (MSWord) file in ObjectiveC? I am writing a printing
Possible Duplicate: Open a file in the proper encoding automatically my code: import csv

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.