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. Create a folder by using C#

Create a folder by using C#

Scheduled Pinned Locked Moved C#
csharptutorialquestion
5 Posts 5 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.
  • J Offline
    J Offline
    jayarajmrj
    wrote on last edited by
    #1

    How do we create a folder by using C#? For example , suppose if we want to create a new folder means , Right click --> New Folder. The same way I want to create a New folder dynamically

    J R C P 4 Replies Last reply
    0
    • J jayarajmrj

      How do we create a folder by using C#? For example , suppose if we want to create a new folder means , Right click --> New Folder. The same way I want to create a New folder dynamically

      J Offline
      J Offline
      Janu_M
      wrote on last edited by
      #2

      we can create a a folder by using the statement Directory.SetCurrentDirectory("C:\\"); Directory.CreateDirectory("Foldername"); Direcotry is a class which is under the System.IO namespace.

      1 Reply Last reply
      0
      • J jayarajmrj

        How do we create a folder by using C#? For example , suppose if we want to create a new folder means , Right click --> New Folder. The same way I want to create a New folder dynamically

        R Offline
        R Offline
        Rupesh Kumar Swami
        wrote on last edited by
        #3

        hi, use following statement DirectoryInfo obDir = new DirectoryInfo(MainDataDirectoryPath); obDir.Create(); hope this helps

        Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)

        1 Reply Last reply
        0
        • J jayarajmrj

          How do we create a folder by using C#? For example , suppose if we want to create a new folder means , Right click --> New Folder. The same way I want to create a New folder dynamically

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          It's just System.IO.Directory.CreateDirectory(@"c:\my directory"); no need to set the current directory ( which is a bad thing to do anyhow, as it can stop the other code from working )

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          1 Reply Last reply
          0
          • J jayarajmrj

            How do we create a folder by using C#? For example , suppose if we want to create a new folder means , Right click --> New Folder. The same way I want to create a New folder dynamically

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            Please - test to see if the directory exists before you attempt to create it:

            if (!Directory.Exists(@"c:\foobar"))
              Directory.CreateDirectory(@"c:\foobar");
            

            Under certain circumstances, you might still get directory name collisions, but with this method you've at least got a fighting chance.

            Deja View - the feeling that you've seen this post before.

            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