Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to grab name of a streamreader

Tags:

c#

In C#, how do you grab the name or path of the streamreader

ie

filein = new StreamReader(@"C:\ee\fff\Desktop\spreadtool\test.csv");

and now I want to regex on the path, how do I reference the above. I know filestreamer has a getname() method but does streamreader? I looked it up and it doesn't seem to have one.

like image 888
user2521358 Avatar asked Nov 27 '22 17:11

user2521358


1 Answers

StreamReader does not have a property that contains the FilePath from which it was created. It may not be created from a file at all (it can be created from a stream). If you want the path, you should store it in a string before you create the StreamReader

String file = @"C:\ee\ccc\Desktop\spreadtool\test.csv"
filein = new StreamReader(file);
String path = Path.GetDirectory(file);
like image 78
Alan Avatar answered Dec 13 '22 10:12

Alan