档案建立 [英] File creation

查看:68
本文介绍了档案建立的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在应用程序exe所在的位置创建文件

例如:

我的应用程序在

d:\ data \ app \ app1.exe

现在我想在执行结束时创建一个文件xyz.txt

d:\ data \ app \ xyz.txt


现在,如果我将我的app1.exe移至c:\,它必须在c:\处创建文件,而无需更改代码.

我该如何实现?

谢谢.....

How can I create a file at the place where the application exe resides

eg :

my app is in

d:\data\app\app1.exe

now I want to create a file say xyz.txt at the end of execution

d:\data\app\xyz.txt


now if I move my app1.exe to c:\ it must create the file at c:\ without any change in code.

How can I achieve this ?

Thanks.....

推荐答案

仅使用文件名作为路径,例如"xyz.txt".
Use just the name of the file as the path, e.g "xyz.txt".


string appPath = Path.GetDirectoryName(Application.ExecutablePath);


这将为您提供当前汇编所在的目录
This will give you the directory the current assemble is in
string myFile = System.AppDomain.CurrentDomain.BaseDirectory+@"\xyz.txt"


这篇关于档案建立的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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