如何从一个C#控制台应用程序目录的路径? [英] How to get a path from a directory in a C# console application?

查看:311
本文介绍了如何从一个C#控制台应用程序目录的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这个文件结构

Soultion-> Folder1中 - > FileIwant.html

Soultion-> Folder1 -> FileIwant.html

所以,这可能是类似于C:\ Soultion \ Folder1中\ FilterIwant.html

So this could be something like C:\Soultion\Folder1\FilterIwant.html

现在我需要阅读这个文件到我的应用程序。我可以在c它不只是硬$ C $,因为当我把它送给别人,他们可能把它放在F:,驱动器或某事

Now I need to read this file into my application. I can't just hardcode it since when I give it to someone else they might put it on F: drive or something.

或者,当我创建一个msi文件的路径可能是完全不同的。所以,我怎么能说可能采取

Or when I create a msi file the path might be completely different. So how can I say maybe take

Folder1中\ FilterIwant.html

"Folder1\FilterIwant.html"

和使用得到的文件夹路径,无论在哪里,他们把它?

and use that to get the folder path regardless of where they put it?

修改

我试过Path.GetFullPath但我降落在的bin / debug目录。但我的文件不在该目录中。我认为它是前一对夫妇的目录。另外,如果我做一个msi文件将我斌/调试目录?

I tried Path.GetFullPath but I land up in the bin/debug directory. But my file is not in that directory. I think it is a couple directories before. Also if I make a msi file will I have bin/debug directory?

推荐答案

为什么是用来作为应用程序的一部分,不是在同一个文件夹中应用程序的文件?这听起来像你对我应该在该文件中设置的属性复制到输出文件夹,当你做一个构建。

Why is a file which is used as part of your application not in the same folder as the application? It sounds to me like you should set the properties on that file to copy to the output folder when you do a build.

否则,将确保您的文件中的的在bin \ debug文件夹。

Doing that will make sure your file is in the bin\debug folder.

编辑: 如果不是这样,你应该把你的文件中的特殊文件夹中的一个,应用数据我的文档春天在脑海中。

either that or you should be placing your files in one of the special folders, app data or my documents spring to mind.

这篇关于如何从一个C#控制台应用程序目录的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆