c# - How do I get/set a winforms application's working directory? -


I'm currently using to get the root of the application:

  path . Get Directional Name (GetExecutingAssembly Assembly) GetName (). CodeBase) .Substring (6)  

But it seems to me scary to get the root directory of the application and the directory that works Is there a better way to set up?

Therefore, you can change the directory using only Envrionment.CurrentDirectory = (the yoga directory). There are several ways to get the original performance director, one way is essentially through the way you described it and through another directory. The gatecontent directory () if you have not changed the directory.

  using the system; Using System.IO; Classroom test {public static zero main () {try {// Get current directory. String path = directory GetCurrentDirectory (); String target = @ "c: \ temp"; Console.light line ("current directory {0}", is the path); If (! Directory.Exists (target)) {Directory.CreateDirectory (target); } // Change the current directory environment. Current directory = (target); If (path.Equals (Directory.GetCurrentDirectory ())) {Console.WriteLine ("You are in a temporary directory."); } Else {Console.WriteLine ("You are not in the temporary directory."); }} Hold (exception e) {Console.WriteLine ("process failed: {0}", e.ToString ()); }}  


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -