如何制作通用文件路径 [英] How to make a common file path

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

问题描述

大家好.

我有问题要问你的想法.

我写了一个操作文件的代码,比如说"filex".工作时我的计算机没有问题,但是当我将程序安装到另一台计算机上时,我必须更改filex的路径才能正常工作.

我正在对filex进行简单的文件操作,仅此而已.

我该怎么做才能克服这个问题?你有什么想法?

我最好的问候...

Hey everyone.

I have question to get your ideas.

I wrote a code that operates a file, let''s say "filex". There is no problem in my computer while working, but when I install my program into an another computer, I have to change the path of filex to work properly.

I''m making simple file operations on filex, nothing more.

What can I do to overcome this? What is your ideas?

My best Regards...

推荐答案

最好从外部源(即配置文件)获取文件路径,因此您可以在运行时更改它而无需重新编译.

您还可以通过获取应用程序目录Directory.GetCurrentDirectory()并在Applications文件夹中构建路径来引用文件.

It is better to get your file paths from an external source ie configuration file, so you can change that at runtime without needing a recompile.

You can also reference your files via getting your applications directory Directory.GetCurrentDirectory() and building your paths in the the applications folder.

app.exe
|-Output 
    |- filex



如果您不愿意使用配置文件,则可以使用可执行文件目录的位置

Hi
If you are reluctant to use config file, you can use the directory of executable file location

var binFolder = new DirectoryInfo(Application.ExecutablePath).Parent;



希望这对您有帮助...



Hope this helps you...


在配置文件中保存文件路径.根据它完成编码.当您在另一台计算机上安装程序时,只需根据计算机更改配置文件的路径即可.
save path of file in config file . done coding according to that. when u install program on another machine just chane the path from config file according to machine.


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

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