开发者

Where will the file without path get created in client system

I have the following code in an Winform Application

 String[] lines = { "LAST MESSAGE", "101" };
 File.WriteAllLines("MPP_Config.txt", lines);

On my Development system, the file gets created under Bin\Debug...

Where will the file be cre开发者_如何学Cated in the client once it is installed in the client system ?

I deploy to a website using Click once Deployment...


I believe it will be created in current working directory of the application. The application might not have access to this directory, especially on systems with UAC, Vista and windows 7. You should probably think about using the application data directory instead.

String[] lines = { "LAST MESSAGE", "101" };
String fileName = Path.combine(System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory,"MPP_Config.txt");
File.WriteAllLines(fileName, lines);


I'm guessing it gets created in the debug folder becuse you have been running it in debug mode. If you ran it in release mode then it will be saved in the bin/release folder.

In other words it will be created in the directory in which the application resides. Why not try it? I.e. copy your exe across...


In the current directory. This means that it might be hard to predict with 100% certainty. If you want to control it, you can use Environment.CurrentDirectory but (as Sam points out in the comments) this may not be a good idea since other code may also depend on the current directory for other purposes.

For instance, the following program will create two different files called "somefile.txt" (given that the exe is not run from the c:\temp directory):

static void Main(string[] args)
{
    File.WriteAllText("somefile.txt", "some text");
    Environment.CurrentDirectory = @"c:\temp";
    File.WriteAllText("somefile.txt", "some text");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜