system.io.directorynotfound ->; 但它在控制台中有效
我的文件是这样引用的(都是相对的):
// WHERE YOU KEEP THE PAGE TITLE XML
public static string myPageTitleXML = "xml/pagetitles.xml";
当我双击可执行文件时,我得到 system.io.directorynotfound和
using (StreamReader r = new StreamReader(myPageTitleXML))
{ //etc.. . .etc....etc..
}
“这个问题需要关闭”。 但从控制台运行它就像一个魅力。 这是怎么回事?
我尝试设置Environment.CurrentDirectory,但无法让任何东西发挥作用。 无论如何我为什么要这么做? 它违背了相对路径的目的不是吗?
响应.. .
“应用程序”在当前上下文中不存在,我将继续尝试人们提到的内容,这不是 windows.form
测试
Path.GetDirectoryName (Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), myPageTitleXML); 给出错误 不支持 URI 格式,Path.GetFullPath() 也是如此。 Server.MapPath 也会导致错误,当前处于离线状态
My files are referenced like so (it's all relative):
// WHERE YOU KEEP THE PAGE TITLE XML
public static string myPageTitleXML = "xml/pagetitles.xml";
and
using (StreamReader r = new StreamReader(myPageTitleXML))
{ //etc.. . .etc....etc..
}
I get system.io.directorynotfound, and "this problem needs to be shut down", when I double click the executable. But running it from the console works like a charm. What's wrong here?
I played around with attempting to set Environment.CurrentDirectory but couldn't get anything to work. Why should I have to do that anyway? It defeats the purpose of a relative path no?
responding.. .
"application" does not exist in the current context, i'll keep trying what people have mentioned, this is not a windows.form
testing
Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), myPageTitleXML); gives error URI formats are not supported, as does Path.GetFullPath(). Server.MapPath results in an error as well, this is currently offline
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设这个目录位于代码执行目录下的某个位置,听起来您可以使用 ..
或
.. 来了解应用程序在搜索“xml”目录时看到的内容其中的“pagetitles.xml”文件。
如果这些方法之一返回的目录没有指向您认为的位置,则您需要移动应用程序的位置或此文件夹的位置,以便它与应用程序位于同一目录中。
希望这能让您走上正确的道路。
Well assuming this directory is somewhere under the directory in which your code is executing, it sounds like you can use ..
or
.. to get an idea as to what your application is seeing when it goes in search of an 'xml' directory with the 'pagetitles.xml' file in it.
If the directory returned by one of these methods does not point where you thought it did, you'll need to move the location of your application or the location of this folder so that it is within the same directory as the app.
Hope this gets you on the right path.
那么,当您通过双击可执行文件运行它时,名为 xml 的文件夹中是否有一个名为 pagetitles.xml 的文件,其中 xml 是与可执行文件位于同一位置的文件夹?
当然可以使用这样的相对路径,但我不会真正推荐它。 相反,也许使用类似的东西:
So, when you run it from double clicking the executable, is there a file named pagetitles.xml in a folder named xml, where xml is a folder in the same location as the executable?
It's certainly possible to use relative paths like this, but I wouldn't really recommend it. Instead, maybe use something like:
这是 ASP.NET 代码吗? 如果是这样,那么您可能需要执行 MapPath("xml/pagetitles.xml")
Is this ASP.NET code? If so then you probably need to do MapPath("xml/pagetitles.xml")