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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:16:15+00:00 2026-06-11T13:16:15+00:00

How do i open a StreamReader with FILE_SHARE_READ , FILE_SHARE_WRITE , FILE_SHARE_DELETE ? Same

  • 0

How do i open a StreamReader with FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_DELETE?


Same question, slightly expanded

How do i open a StreamReader so that i can read an encoded text file, with sharing options so that another process can read the file?

How do i open a StreamReader so that i can read an encoded text file, with sharing options so that another process can modify the file while i’m reading it?

How do i open a StreamReader so that i can read an encoded text file, with sharing options so that another process can delete the file while i’m reading it?


Same question, slightly more expanded

In the .NET Framework class library there is a class called StreamReader. It is the only class designed to read “text”, which is why it descends from the abstract base TextReader class. The TextReader/StreamReader allows you to specify the encoding used by the file you are trying to open, and can decode the file for you, returning Strings of text.

Once i’ve opened a file with the StreamReader:

var sr = new StreamReader(path);

The file is locked, with other processes unable to modify or delete the file. What i need is the equivalent of a FileStream class’s FileShare enumeration:

  • None: Declines sharing of the current file. Any request to open the file (by this process or another process) will fail until the file is closed.
  • Read“: Allows subsequent opening of the file for reading. If this flag is not specified, any request to open the file for reading (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file.
  • Write: Allows subsequent opening of the file for writing. If this flag is not specified, any request to open the file for writing (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file.
  • ReadWrite:Allows subsequent opening of the file for reading or writing. If this flag is not specified, any request to open the file for reading or writing (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file.
  • Delete: Allows subsequent deleting of a file.

Except that, for obvious reasons, i cannot use a FileStream – have to use a StreamReader.

How can i open a StreamReader with FileShare.ReadWrite | FileShare.Delete?

  • 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-11T13:16:17+00:00Added an answer on June 11, 2026 at 1:16 pm

    StreamReader has a constructor that can take a stream. So instead of using the constructor that takes a string path, first create a FileStream with the options that you want, then pass that FileStream to the StreamReader constructor.

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

Sidebar

Related Questions

This doesnt work: string fileContent = Resource.text; StreamReader read = File.OpenText(fileContent); string line; char[]
I have this code 'Open a file for reading 'Get a StreamReader class that
What i'm trying to do is open every text file in a directory, read
I'm using the FileStream and StreamReader classes like so: using(FileStream stream = File.Open(filePath,FileMode.Open,FileAccess.Read,FileShare.ReadWrite)) {
I have a text file that I want to read line by line and
I want to open a txt file and read from it here's the code:
I read a text file from the hard drive, then I want to put
I want to read a text file line by line. I wanted to know
How can I open any file, specified by a path, in ASP.NET programatically? I
I need to continuously read a log file to detect certain patterns. How can

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.