creating a directory in the solution during runtime
-
hi, I'm using this code to create a new directory into the solution during runtime string targetPath = @"SampleDirectory"; \\directory name without any path to be copied in the solution Directory.CreateDirectory(targetPath); this code is working very well & creates the directory into the solution, but the problem arouses whenever I'm using an open file dialogue before this code, in this case the directory is created into the path specified by the open file dialogue not the solution path. what can I do?
-
hi, I'm using this code to create a new directory into the solution during runtime string targetPath = @"SampleDirectory"; \\directory name without any path to be copied in the solution Directory.CreateDirectory(targetPath); this code is working very well & creates the directory into the solution, but the problem arouses whenever I'm using an open file dialogue before this code, in this case the directory is created into the path specified by the open file dialogue not the solution path. what can I do?
Hi, You can maintain your solution path in a configuration file, namely App.Config.. Have a class that reads the xml file and get the path assigned to a property.. U can then use this property in your code wherever you wish to use the solution's path... Hope this helps... :)
-
hi, I'm using this code to create a new directory into the solution during runtime string targetPath = @"SampleDirectory"; \\directory name without any path to be copied in the solution Directory.CreateDirectory(targetPath); this code is working very well & creates the directory into the solution, but the problem arouses whenever I'm using an open file dialogue before this code, in this case the directory is created into the path specified by the open file dialogue not the solution path. what can I do?
Environment.CurrentDirectory[^] perhaps?
Cheers, Vikram.
Current activities: Films: The classic Pink Panther series TV series: Friends, season 3 Books: Liar's Poker, by Michael Lewis.
Carpe Diem.
-
hi, I'm using this code to create a new directory into the solution during runtime string targetPath = @"SampleDirectory"; \\directory name without any path to be copied in the solution Directory.CreateDirectory(targetPath); this code is working very well & creates the directory into the solution, but the problem arouses whenever I'm using an open file dialogue before this code, in this case the directory is created into the path specified by the open file dialogue not the solution path. what can I do?
Your code is assuming that the Current Directory is your "solution" path. This is not that case and you should NOT be relying on it. ALWAYS build a fully qualified path to the target folder/file you want when doing file I/O operations. In your case, I'm assuming you want the new folder to be created in the same folder as your .EXE file. To get the full path to that folder, you can use
Application.StartupPath
. Then you can usePath.Combine(...)
with that path and your new folder name to create the fully qualified path to this new folder and pass that to CreateDirectory.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Your code is assuming that the Current Directory is your "solution" path. This is not that case and you should NOT be relying on it. ALWAYS build a fully qualified path to the target folder/file you want when doing file I/O operations. In your case, I'm assuming you want the new folder to be created in the same folder as your .EXE file. To get the full path to that folder, you can use
Application.StartupPath
. Then you can usePath.Combine(...)
with that path and your new folder name to create the fully qualified path to this new folder and pass that to CreateDirectory.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008thanks a lot, I used the Application.StartupPath and Path.Combine() and it's working very well.