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. creae directory and copy file in this directory

creae directory and copy file in this directory

Scheduled Pinned Locked Moved C#
csharp
8 Posts 6 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.
  • T Offline
    T Offline
    tanzeel85
    wrote on last edited by
    #1

    hi all...i have to create directory in win7 and copy file in this directory programmatically in using c#..my application properly work in winXP...but when i run my application in win7..it does not create directory as well as copy file...tell me what i do for win7....it is a C# windows desktop application... regards tanzeel

    L 1 Reply Last reply
    0
    • T tanzeel85

      hi all...i have to create directory in win7 and copy file in this directory programmatically in using c#..my application properly work in winXP...but when i run my application in win7..it does not create directory as well as copy file...tell me what i do for win7....it is a C# windows desktop application... regards tanzeel

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      In win7 you need to give admin access (or you need to run your windows application as an administrator) to your application to allow it to create directory. Hope this will help!

      Jinal Desai - LIVE Experience is mother of sage....

      S T 2 Replies Last reply
      0
      • L Lost User

        In win7 you need to give admin access (or you need to run your windows application as an administrator) to your application to allow it to create directory. Hope this will help!

        Jinal Desai - LIVE Experience is mother of sage....

        S Offline
        S Offline
        Swiftain
        wrote on last edited by
        #3

        what error do you get?

        T 1 Reply Last reply
        0
        • S Swiftain

          what error do you get?

          T Offline
          T Offline
          tanzeel85
          wrote on last edited by
          #4

          there is no error occur...application execute successfully but did not create directory in win7

          1 Reply Last reply
          0
          • L Lost User

            In win7 you need to give admin access (or you need to run your windows application as an administrator) to your application to allow it to create directory. Hope this will help!

            Jinal Desai - LIVE Experience is mother of sage....

            T Offline
            T Offline
            tanzeel85
            wrote on last edited by
            #5

            i login from administrator user but did not create directory in win7

            M M L 3 Replies Last reply
            0
            • T tanzeel85

              i login from administrator user but did not create directory in win7

              M Offline
              M Offline
              Mirko1980
              wrote on last edited by
              #6

              Can you show us your code?

              1 Reply Last reply
              0
              • T tanzeel85

                i login from administrator user but did not create directory in win7

                M Offline
                M Offline
                Michel Godfroid
                wrote on last edited by
                #7

                Logging in is not enough to be an administrator. You should run your program as administrator. Also if your program does not give your an error message, it's probably because you aren't checking for any errors. (boo! boo!). If it fails to create a directory, you should not be creating your directory there in the first place (Places like the root of c:, program files, windows, etc... are taboo.

                1 Reply Last reply
                0
                • T tanzeel85

                  i login from administrator user but did not create directory in win7

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  AFAIK the situation is the same on Vista and Windows 7, and will continue to be so on newer versions of Windows: - a lot of directories cannot be modified by a regular user; those include the top-level directory of your system partition (usually C: ) and all important directories such as /Windows, /Windows/system32, and /Program Files. - as Michel said, you need an administrator account AND an app "running as administrator" so get over those restrictions. What should work though is access to a number of special folders intended to hold your app's settings and local data, and other things like that. Have a look at Environment.GetFolderPath() and Environment.SpecialFolder Within such directories, one usually creates a hierarchy of folders, so a typical sequence would be:

                  string fileSpec=Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+
                  	@"\\companyName\\appName\\logfile.txt";
                  string folder=Path.GetDirectoryName(fileSpec);
                  Directory.CreateDirectory(folder);  // no need to test existence first!
                  StreamWriter writer=File.CreateText(fileSpec);
                  ...
                  

                  :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  Prolific encyclopedia fixture proof-reader browser patron addict?
                  We all depend on the beast below.


                  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