TextWriter 和基本文件夹文件
我已将一个文本文件添加到我的项目中,打算使用它来包含从本地页面上的表单中获取的字符串 - 我的意思是,您将字符串输入到文本字段中,单击按钮,然后使用 TextWriter 将字符串写入entries.txt就像我在 C# 中一直做的那样。问题是,当我给出“entries.txt”作为参数时,它不会将数据保存到相关 *.aspx 文件所在的同一文件夹中的entries.txt(即项目的文件夹),但是,对于一些奇怪的情况原因,在 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE 中创建一个新的 txt 文件。所以我想我需要提供文件的完整路径。我不能只给出 HDD 上项目的路径,因为我需要在不同的计算机上打开它,所以我根据 *.aspx 文件的地址尝试了 @"localhost:2439/WebSite1/entries.txt",但是它不起作用。对于与带有代码的文件位于同一文件夹中的文件,我应该给出什么路径?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看
Server.MapPath()
,它将网站路径映射到本地物理路径。Check out
Server.MapPath()
, which will map a website path to the local, physical path.