Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StreamReader defaults to c:\windows\system32\

Status
Not open for further replies.

lumstar

Technical User
Jan 29, 2002
177
CA
Hi again,

When I use a StreamReader to open a file as follows:

StreamReader finschema = new StreamReader("dispPubs.xsl");

I get the following error:

Could not find file "C:\WINDOWS\system32\dispPubs.xsl"

Is there any way to open a file in the current directory without hardcoding it?

Thanks.



Lumstar
______________________________________
And The Star Continues To Shine....
 
Application.ExecutablePath

You can pull the path from this and locate as necessary.

I haven't looked but there may be a different property from Application too. Application.xxxxx

 
try this
Code:
//if you do not specify the path it will take a filename
//and look in the current directory
string path = "textfile.txt";
//string path = @"C:\marty\CSharp\textfile.txt";
using (StreamReader str = new StreamReader((System.IO.Stream)File.OpenRead(path)))
Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top