C#如何设置启动路径 [英] C# How to set startup path

查看:460
本文介绍了C#如何设置启动路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用c#创建一个Windows应用程序。因为我正在播放要在媒体播放器中播放的视频文件,但在设计时我正在给出URL =D \\Video \\abc.avi。

制作该应用程序的exe后我在C驱动器上运行exe的路径然后它将创建错误播放视频文件,因为在视频文件的URL路径是D驱动器并保存在C驱动器上的设置。

请帮帮我。抱歉,我的英语很弱。

解决方案

string Path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)



它将为您提供ApplicationData文件夹的路径,该文件夹在不同的操作系统中很常见


您可以使用以下代码:



string path = @\ myvideo.wmv;



path = Application.StartupPath + path;



它将始终自动到达Debug文件夹,如果您已创建设置,那么它将是您的应用程序的.exe文件在运行时所在的路径。请记住将视频放在Drivename:\ Project1 \\\\Debug \文件夹中,即您的视频必须位于调试文件夹中。



希望其有用

I am creating a Windows application in c#. In that i am playing video files to play in media player but at the time of design I am giving URL="D\\Video\\abc.avi".
after making exe of that application i am giving path to run exe on C Drive then it will create error to play video file because in URL path of video file is D drive and save setup on C Drive.
please help me. Sorry My English is weak.

解决方案

string Path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

it will give you the path of the ApplicationData folder which is common in different OS


You may use this code:

string path= @"\myvideo.wmv";

path = Application.StartupPath + path;

it will always reach the Debug folder automatically and if you have created the setup, then it will be the path where your application's .exe file is situated at runtime. Remember to place your video in "Drivename:\Project1\bin\Debug\" folder i.e. your video must be in Debug folder.

Hope its helpful.


这篇关于C#如何设置启动路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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