471,330 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Getting path from a StreamReader

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?

Jul 21 '05 #1
1 2811
<wa****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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
}
}
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tom | last post: by
3 posts views Thread by Beryl Small | last post: by
4 posts views Thread by Larry Tate | last post: by
1 post views Thread by waolly | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.