A
A
anonymous2017-07-13 10:53:30
.NET
anonymous, 2017-07-13 10:53:30

How to open ReadOnly file?

I need to make the file open read-only
found information about it

using (TextReader reader = new StreamReader(File.OpenRead(Path.Combine(client._WorkLogFileLoc, "dump.txt")))) {     
         //do stuff 
     }

But I don't know what client._WorkLogFileLoc does
Help a beginner)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2017-07-13
@anonymouss

var file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); 
using (var stream = new StreamReader(file))
{
    //код
}

A
Alexander Kuznetsov, 2017-07-13
@DarkRaven

Everything is very simple.
just builds the path by joining two parts - the path part from client._WorkLogFileLoc and "dump.txt" .
For example, let 's say client._WorkLogFileLoc property contains "D:\some\path\to\folder", as a result we get
Path.Combine("D:\some\path\to\folder", "dump.txt"), which will give:
"D:\some\path\to\folder\dump.txt"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question