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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:59:16+00:00 2026-05-11T17:59:16+00:00

I have some .csv files which I’m using as part of a test bench.

  • 0

I have some .csv files which I’m using as part of a test bench. I can open them and read them without any problems unless I’ve already got the file open in Excel in which case I get an IOException:

System.IO.IOException : The process cannot access the file ‘TestData.csv’ because it is being used by another process.

This is a snippet from the test bench:

using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(fullFilePath, FileMode.Open, FileAccess.Read)), false))
{
    // Process the file
}

Is this a limitation of StreamReader? I can open the file in other applications (Notepad++ for example) so it can’t be an O/S problem. Maybe I need to use some other class? If anyone knows how I can get round this (aside from closing excel!) I’d be very grateful.

  • 1 1 Answer
  • 1 View
  • 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-05-11T17:59:16+00:00Added an answer on May 11, 2026 at 5:59 pm

    As Jared says, You cannot do this unless the other entity which has the file open allows for shared reads. Excel allows shared reads, even for files it has open for writing. Therefore, you must open the filestream with the FileShare.ReadWrite parameter.

    The FileShare param is often misunderstood. It indicates what other openers of the file can do. It applies to past as well as future openers. Think of FileShare not as a retroactive prohibition on prior openers (eg Excel), but a constraint that must not be violated with the current Open or any future Opens.

    In the case of the current attempt to open a file, FileShare.Read says “open this file for me successfully only if it any prior openers have opened it only for Read.” If you specify FileShare.Read on a file that is open for writing by Excel, your open will fail, as it would violate the constraint, because Excel has it open for writing.

    Because Excel has the file open for writing, you must open the file with FileShare.ReadWrite if you want your open to succeed. Another way to think of the FileShare param: it specifies “the other guy’s file access”.

    Now suppose a different scenario, in which you’re opening a file that isn’t currently opened by any other app. FileShare.Read says “future openers can open the file only with Read access”.

    Logically, these semantics make sense – FileShare.Read means, you don’t want to read the file if the other guy is already writing it, and you don’t want the other guy to write the file if you are already reading it. FileShare.ReadWrite means, you are willing to read the file even if the another guy is writing it, and you have no problem letting another opener write the file while you are reading it.

    In no case does this permit multiple writers. FileShare is similar to a database IsolationLevel. Your desired setting here depends on the “consistency” guarantees you require.

    Example:

    using (Stream s = new FileStream(fullFilePath, 
                                     FileMode.Open,
                                     FileAccess.Read,
                                     FileShare.ReadWrite))
    {
      ...
    }
    

    or,

    using (Stream s = System.IO.File.Open(fullFilePath, 
                                          FileMode.Open, 
                                          FileAccess.Read, 
                                          FileShare.ReadWrite))
    {
    }
    

    Addendum:

    The documentation on System.IO.FileShare is a little slim. If you want to get the straight facts, go to the documentation for the Win32 CreateFile function, which explains the FileShare concept better.

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

Sidebar

Related Questions

I need to open some new csv files on the fly, depending on what
I have some code that creates a CSV file. The order of the rows
I have a huge report coming out of a tool from which i extract
Internally our PHP application uses UTF-8, and we do processing on .csv files and
hi so this is the setup: i need to update some prices from a
This turned out to be more difficult than I thought. Basically, each day a
What I'm trying to do is export a view/table from Sybase ASE 12.0 into
So I'm trying to get the results from a stored proc (200k rows+) into
I am working on a calculation project with lots of scientific, domain specific knowledge.
We've been collecting user data on our site for a while and now we'd

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.