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. Problems with File

Problems with File

Scheduled Pinned Locked Moved C#
question
9 Posts 3 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
    tiwal
    wrote on last edited by
    #1

    I am trying to create a file on a directory where I have total power. The File.Create (..) (as well as any other attempt to create the file even using FileStream()) always fails with the UnauthorizedException . This is not possible since I have permission to write and create files on that directory (after all I can easily create a file by hand there). Is there an explaination ?

    L OriginalGriffO 2 Replies Last reply
    0
    • T tiwal

      I am trying to create a file on a directory where I have total power. The File.Create (..) (as well as any other attempt to create the file even using FileStream()) always fails with the UnauthorizedException . This is not possible since I have permission to write and create files on that directory (after all I can easily create a file by hand there). Is there an explaination ?

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

      tiwal wrote:

      This is not possible since I have permission to write and create files on that directory (after all I can easily create a file by hand there).

      Lousy way to test. Does your code run under YOUR credentials? What path and filename are you trying to write to?

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

      T 1 Reply Last reply
      0
      • T tiwal

        I am trying to create a file on a directory where I have total power. The File.Create (..) (as well as any other attempt to create the file even using FileStream()) always fails with the UnauthorizedException . This is not possible since I have permission to write and create files on that directory (after all I can easily create a file by hand there). Is there an explaination ?

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Depends on what user the application is running under, rather than what access you have. If this is winforms, then I would expect it to run under your user, but a service won't, for example. Double check the folder address, and check the user ID it runs under - if it is complaining, then it is doing so for a reason!

        If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        T 1 Reply Last reply
        0
        • L Lost User

          tiwal wrote:

          This is not possible since I have permission to write and create files on that directory (after all I can easily create a file by hand there).

          Lousy way to test. Does your code run under YOUR credentials? What path and filename are you trying to write to?

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

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

          I am running a debug instance of my program. VS runs under my credentials. The path is simply the debug folder of the application. This is the same path where I was successfully reading and writing, yesterday, using the same VS, and NO change has been made since .

          L 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Depends on what user the application is running under, rather than what access you have. If this is winforms, then I would expect it to run under your user, but a service won't, for example. Double check the folder address, and check the user ID it runs under - if it is complaining, then it is doing so for a reason!

            If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

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

            I am not sure I am understanding well. Tou mean , checking the folder I am trying to write to ?

            OriginalGriffO 1 Reply Last reply
            0
            • T tiwal

              I am running a debug instance of my program. VS runs under my credentials. The path is simply the debug folder of the application. This is the same path where I was successfully reading and writing, yesterday, using the same VS, and NO change has been made since .

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

              tiwal wrote:

              This is the same path where I was successfully reading and writing, yesterday, using the same VS, and NO change has been made since

              If the universe did not change it would behave the same. Something changed. Are you running a copy off the application outside the debugger? Viewing the file using a viewer that could "lock" the file?

              tiwal wrote:

              VS runs under my credentials.

              There's no "run as admin"-shield on the taskbar-icon?

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

              T 1 Reply Last reply
              0
              • T tiwal

                I am not sure I am understanding well. Tou mean , checking the folder I am trying to write to ?

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                Check the name, yes - make sure that the folder you are trying to write to is exactly the folder you think it is.

                If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                1 Reply Last reply
                0
                • L Lost User

                  tiwal wrote:

                  This is the same path where I was successfully reading and writing, yesterday, using the same VS, and NO change has been made since

                  If the universe did not change it would behave the same. Something changed. Are you running a copy off the application outside the debugger? Viewing the file using a viewer that could "lock" the file?

                  tiwal wrote:

                  VS runs under my credentials.

                  There's no "run as admin"-shield on the taskbar-icon?

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

                  T Offline
                  T Offline
                  tiwal
                  wrote on last edited by
                  #8

                  Something has changed for sure . But if I were the one who changed that something I wouldn't be here to pose this question. I am not running anything which may lock the file. After all the file cannot even be created. Running the environment as administrator even worsened things, as now the path of the file changed to something "like" root ("C:.\filename", which doen not even elaborate to a regular path).

                  L 1 Reply Last reply
                  0
                  • T tiwal

                    Something has changed for sure . But if I were the one who changed that something I wouldn't be here to pose this question. I am not running anything which may lock the file. After all the file cannot even be created. Running the environment as administrator even worsened things, as now the path of the file changed to something "like" root ("C:.\filename", which doen not even elaborate to a regular path).

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

                    tiwal wrote:

                    as now the path of the file changed to something "like" root ("C:.\filename", which doen not even elaborate to a regular path).

                    I would suggest you have a bug in your code which is leading to an invalid path somewhere. Use your debugger to step throught the code and see the exact values of the variables that are used to create the path.

                    One of these days I'm going to think of a really clever signature.

                    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