Getting path from a StreamReader

  • Thread starter Thread starter waolly
  • Start date Start date
W

waolly

I have a function which gets passed a streamreader object as an
argument (I know this might sound a little weird, but it's to avoid
code repetition). My problem is this - given a streamreader object is
it possible to determine the file path the streamreader is referencing?
 
I have a function which gets passed a streamreader object as an
argument (I know this might sound a little weird, but it's to avoid
code repetition). My problem is this - given a streamreader object is
it possible to determine the file path the streamreader is referencing?

Only if the StreamReader is reading a FileStream:

private string GetFileName(StreamReader reader) {
FileStream fileStream = reader.BaseStream as FileStream;
if(fileStream != null) {
return fileStream.Name;
} else {
// Handle no file situation
}
}
 
Back
Top