文件路径的项目文件? [英] File path for project files?

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

问题描述

我工作的媒体播放器在C#中,但我想我的测试中,我有一个问题。

I am working on a media player in C# but when I want to make my test I have a problem.

我要创建一个新的对象歌以下路径:

I have to create a new object song with the following path:

@"C:\Users\Jesus Antonio\Desktop\JukeboxV2.0\JukeboxV2.0\Datos\ich will.mp3"

它的工作原理,但是当我换电脑我不得不重写整个路径, 我的项目被称为JukeboxV2.0

It works but when I change the computer I have to rewrite the entire path, My project is called JukeboxV2.0

在java中我还记得你可以随便写,例如路径

In java I remember you can just write the path for example

@"JukeboxV2.0\JukeboxV2.0\Datos\ich will.mp3"

这将节省大量的时间,因为我可以把我的项目,不同的计算机和它的作品,但在这里我不知道如何做到这一点,谁知道?

This will save a lot of time because I can take my project to different computers and it works, but here I don't known how to do that, anyone know?

推荐答案

您会做这样的事情进去你的应用环境文件夹的路径数据\ ich_will.mp3。

You would do something like this to get the path "Data\ich_will.mp3" inside your application environments folder.

string fileName = "ich_will.mp3";
string path = Path.Combine(Environment.CurrentDirectory, @"Data\", fileName);

在我的情况下,将返回以下内容:

In my case it would return the following:

C:\MyProjects\Music\MusicApp\bin\Debug\Data\ich_will.mp3

我用 Path.Combine Environment.CurrentDirectory 在我的例子。这些都是非常有用的,并允许您构建基于应用程序的当前位置的路径。 Path.Combine 将两个或多个字符串创建一个位置,而 Environment.CurrentDirectory 为您提供的工作目录您的应用程序。

I use Path.Combine and Environment.CurrentDirectory in my example. These are very useful and allows you to build a path based on the current location of your application. Path.Combine combines two or more strings to create a location, and Environment.CurrentDirectory provides you with the working directory of your application.

工作目录是不一定相同的路径,你的执行的位置,但在大多数情况下,它应该是,除非另有规定。

The working directory is not necessarily the same path as where your executable is located, but in most cases it should be, unless specified otherwise.

这篇关于文件路径的项目文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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