加载文件时出现问题
我编写了一个加载文本文件的程序。效果很好。 我尝试将我的程序放入安装程序(Visual Studio .Net2008 )中,当我在 x64 位 Windows 7 中运行我的程序时,我的程序无法工作,因为它尝试读取下面的位置,但无法访问该文件,请问可以吗给我建议?
** 动态创建的文件路径!!!
string FILEPATH = Directory.GetCurrentDirectory() + "\\GameData\\savedata.ahd";
结果是这样的!从这一次我的程序无法加载txt文件!但在 C:\program Files\FTE\Co... 我没有任何问题!
C:\Program Files (x86)\FTE\CoTM\GameData\savedata.ahd
I wrote one program that load a text file. it work well.
I try to put my program in installer(visual studio .Net2008 ), when I run my program in x64 bit windows 7,my program cannot work because, it try to read below location but it can not access to the file, would you please advice me?
** path of the file creating dynamically!!!
string FILEPATH = Directory.GetCurrentDirectory() + "\\GameData\\savedata.ahd";
the result is this!from this pass my program cannot load the txt file! but in C:\program Files\FTE\Co... I dont have any problem!
C:\Program Files (x86)\FTE\CoTM\GameData\savedata.ahd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您遇到访问问题,因为 Windows 7 不允许您访问 Program Files 目录,请参阅此处以获取更多信息以及应将文件存储在何处:http://windowsteamblog.com/windows/b/developers/archive/2009/08/ 04/用户帐户控制数据重定向.aspx
You're having access problems, because Windows 7 won't let you access the Program Files directory, see here for more information, and where you should store the files: http://windowsteamblog.com/windows/b/developers/archive/2009/08/04/user-account-control-data-redirection.aspx
您应该将该文件作为资源添加到安装程序中或将其放在安装程序的同一目录级别中。设置中的硬编码文件路径不适用于您以外的计算机。
you should add the file as a resource to the installer or put it within the same directory level of the installer. Hard coding file paths within setups dont work on machines other than yours.