C#可执行文件执行目录 [英] C# Executable Executing directory

查看:158
本文介绍了C#可执行文件执行目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是获得C#可执行文件运行路径的最佳方法

What is the best method of getting the path the C# executable is running from?

我需要使用它的临时文件夹等,目前我使用:

I need to use it for temp folders etc and currently I'm using:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)

但后来我需要做:

.Replace("file:\\", string.Empty)

,因为这给了我一个URI类型的路径(即有文件:\在开始)。这是不可用的我的代码其他一些地方

as this gives me a URI type path (i.e. has file:\ at the start) which is unusable with some other parts of my code.

推荐答案

不能准确回答你的问题,但是我会建议看看:

Not an accurate answer to your question, however I would suggest to have a look at:

Path.GetTempFileName()

http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename.aspx

这篇关于C#可执行文件执行目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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