I am writing a program that copies files to different folders. The folder from which I copy the files should be created and lie in the project folder (screen). I need to create this folder in the project working directory. enter image description here]

  • the screen is completely "unwatchable" - Sublihim
  • The problem is what? - vitidev
  • try to increase it and everything there will be "Watchable" .... the problem is that I don’t know how to create a project folder in the project itself ..... Ie. I need that I could just copy the project along with the exe-nick and not bathe that on drive C for example, I have created a folder for the files that need to be copied .... this folder needs to be created for example you need to create in the project folder .... - Ildarik07
  • No, something is not right. On the client machine, the entire project will not unfold, but only executable files (well, and possibly supporting files), but certainly not the source code. What is your real challenge? - VladD
  • @Ildarik07 update the question body instead of writing comments. - αλεχολυτ

2 answers 2

To know for sure the path to the directory of the executable file (and I suspect that this is exactly what you are trying to find out), use System.Reflection .
The value of the Location property should be obtained from an instance of the Assembly class. It will look like this:

 var location = System.Reflection.Assembly.GetExecutingAssembly().Location; //Для выделения пути к каталогу, воспользуйтесь `System.IO.Path`: var path = Path.GetDirectoryName(location); 

Accordingly, if the path to your file looks like this: C:\ScriptInWork\MySuperApp.exe , then as a result of executing the above code, in the path variable you will get C:\ScriptInWork

  • Can you please leave a more informative answer? - Vadim Ovchinnikov
  • @VadimOvchinnikov, of course. I will get to the computer, be sure to expand and add - Sublihim

The folder that appears in the project will still be physically located on the disk where your project is located. Only decision folders are not created. Therefore, create a folder in the directory where your project is located and in the Solution Explorer click the "Show all files" toggle toggle. And you take away your folder.

  • In general, I finally need to get: copy the project to disk c and create a folder inside the project folders ..... - Ildarik07
  • Project or application? - Sublihim
  • Write where exactly, I'll post the code to you - Yury Bakharev
  • C: \ ScriptInWork for example - Ildarik07
  • public void DirCreate () {// Path to the disk where the directory where the files are stored is created Puth = @ "C: \ WebMonFiles"; DirectoryInfo directoryInfo = directory DirectoryInfo (Puth); if (! directoryInfo.Exists) {directoryInfo.Create (); }} that's what it is now - Ildarik07