TextWriter and base folder files
I have added a text file to my project with intend of using it to contain strings taken from the form on the local page - I mean, you input the string into textfield, hit the button and the string is written with TextWriter into entries.txt just the way I always did it in C#. The problem is that when I give "entries.txt" as an argument it doesn't save the data to entries.txt in the same folder where *.aspx file in question is (that is, project's folder) but, for some weird reason, creates a new txt file in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE. So I guess I need to give a full path to the file. I can't just give the path to the project on my HDD because I need to open it on different computers so I tried @"localhost:2439/WebSite1/entries.txt" based on the address of the *.aspx file, but it doesn't work. What path should I give for file that is in 开发者_运维问答the same folder as the file with code?
Check out Server.MapPath()
, which will map a website path to the local, physical path.
精彩评论