【发布时间】:2012-10-08 06:27:51
【问题描述】:
我有一个存储一些站点链接的文件。直到现在我都用过:
string path = Environment.CurrentDirectory + "/forumlinks.txt";
但我想将文件存储在发布文件夹中以便我可以更改它,并且我知道它将为用户永久更改。
所以我改成这样:
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"/forumlinks.txt";
但我得到一个例外:
System.IO.FileNotFoundException。
我的问题:这是从发布文件夹中获取文件的正确方法吗?我应该重新考虑一下并将他存放在不同的地方吗?如果是这样,我会很高兴听到这个消息。
【问题讨论】:
-
你用的是winforms、asp.net还是什么?
标签: c# asp.net file exception-handling path