Thanks!
You're right.
I will use the 'is' keyword to really see if it is a FileStream and if yes,
I will cast it and use the 'Name' property.
In fact, I need to know it because I have a 'TextWriterTraceListener' that
is used for logging purpose. I want to implement a timer that will remove
it from the Tracing Collection, flush it, close it and rename the file with
a timestamp. It will then create a fresh file (with inital name) and add it
again to the Tracing collection.
In this way, I want to implement a 'kind of generic' log file versioning in
my logging class used by several applications.
José
José Joye said:
I have a instance of a StreamWriter and I need to get the path and filename
to which it is attached to.
This sounds easy....
I feel a bit idiot not finding it!
There's no guarantee that it's writing to a file in the first place. It
could be writing directly into a MemoryStream, for instance. You could
use StreamWriter.BaseStream to get the stream it's writing to, and if
that's a FileStream, cast it to that and look at the Name property. Why
do you need to know though?