I am using the st开发者_StackOverflow中文版reamreader 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????
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.
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
精彩评论