Question

I am using the streamreader to read from a file in the project..

StreamReader stRead = new StreamReader("textfile.txt");

        while (!stRead.EndOfStream)
        {
            CheckBoxList1.Items.Add(stRead.ReadLine());
        }

but i get an error:

Could not find file 'c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\textfile.txt'.

whereas the textfile is in my bin folder of the project.

C:\Users\xyz\Documents\Visual Studio 2008\Projects\WebApplication3\WebApplication3\bin\testfile.txt

If i use this path it works but i dont want to use the complete path...

Is there a way to do this???

thanks

how do i store the path as a reference in web.config file????

Was it helpful?

Solution

Maybe you must use

StreamReader stRead = new StreamReader(Server.MapPath("~/textfile.txt"));

to resolve the physical position of your file, supposing it's placed in the root of your project.

OTHER TIPS

I would try the project root directory, otherwise, define the path prefix in a configuration file like your web.config, that way if you're worried about path changes it isn't hard-coded

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top