Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. creating a directory in the solution during runtime

creating a directory in the solution during runtime

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MustafaHamed
    wrote on last edited by
    #1

    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?

    R V D 3 Replies Last reply
    0
    • M MustafaHamed

      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?

      R Offline
      R Offline
      ramz_g
      wrote on last edited by
      #2

      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... :)

      1 Reply Last reply
      0
      • M MustafaHamed

        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?

        V Offline
        V Offline
        Vikram A Punathambekar
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M MustafaHamed

          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?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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 use Path.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

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            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 use Path.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

            M Offline
            M Offline
            MustafaHamed
            wrote on last edited by
            #5

            thanks a lot, I used the Application.StartupPath and Path.Combine() and it's working very well.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups