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. UnauthorizedAccessException

UnauthorizedAccessException

Scheduled Pinned Locked Moved C#
helpquestioncsharpsecuritydebugging
6 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.
  • S Offline
    S Offline
    sjembek
    wrote on last edited by
    #1

    Hi, I'm buidling a forms application in which user settings can be stored and loaded from a file. So far so good. Now I'm trying to load a file of this type made by another user on another computer. It seems this causes some kind security problem: System.UnauthorizedAccessException: Access to the path 'C:\dotnet\myapp\bin\Debug\settings\defaults.set' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.Open(String path, FileMode mode) The file in question is created simply as:

    Stream stream = File.Open(filename, FileMode.Create);
    BinaryFormatter bFormatter = new BinaryFormatter();
    // serialize some stuff
    stream.Close();

    Why am I getting this error and does anyone know how to solve it?

    L V 2 Replies Last reply
    0
    • S sjembek

      Hi, I'm buidling a forms application in which user settings can be stored and loaded from a file. So far so good. Now I'm trying to load a file of this type made by another user on another computer. It seems this causes some kind security problem: System.UnauthorizedAccessException: Access to the path 'C:\dotnet\myapp\bin\Debug\settings\defaults.set' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.Open(String path, FileMode mode) The file in question is created simply as:

      Stream stream = File.Open(filename, FileMode.Create);
      BinaryFormatter bFormatter = new BinaryFormatter();
      // serialize some stuff
      stream.Close();

      Why am I getting this error and does anyone know how to solve it?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      It most likely inherited rights from the parent folder, and got transfered somehow. Are you using Vista btw? I have seen the same thing happen there without explaination.**

      xacc.ide-0.2.0 preview - Now in 100% C# goodness

      **

      S 1 Reply Last reply
      0
      • L leppie

        It most likely inherited rights from the parent folder, and got transfered somehow. Are you using Vista btw? I have seen the same thing happen there without explaination.**

        xacc.ide-0.2.0 preview - Now in 100% C# goodness

        **

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

        No, I'm not using Vista, but this would be a reasonable explanation: I think the user that created the file had the application installed into a folder on his desktop, which could mean the rights to his desktop stick to the file. Can anyone confirm this?

        L 1 Reply Last reply
        0
        • S sjembek

          Hi, I'm buidling a forms application in which user settings can be stored and loaded from a file. So far so good. Now I'm trying to load a file of this type made by another user on another computer. It seems this causes some kind security problem: System.UnauthorizedAccessException: Access to the path 'C:\dotnet\myapp\bin\Debug\settings\defaults.set' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.Open(String path, FileMode mode) The file in question is created simply as:

          Stream stream = File.Open(filename, FileMode.Create);
          BinaryFormatter bFormatter = new BinaryFormatter();
          // serialize some stuff
          stream.Close();

          Why am I getting this error and does anyone know how to solve it?

          V Offline
          V Offline
          Vasudevan Deepak Kumar
          wrote on last edited by
          #4

          Is the file readOnly? Vasudevan Deepak Kumar Personal Homepage namespace LavanyaDeepak
          Personal Weblog
          The World of Deepak and Lavanya
          Views and Reviews

          S 1 Reply Last reply
          0
          • V Vasudevan Deepak Kumar

            Is the file readOnly? Vasudevan Deepak Kumar Personal Homepage namespace LavanyaDeepak
            Personal Weblog
            The World of Deepak and Lavanya
            Views and Reviews

            S Offline
            S Offline
            sjembek
            wrote on last edited by
            #5

            Nope.

            1 Reply Last reply
            0
            • S sjembek

              No, I'm not using Vista, but this would be a reasonable explanation: I think the user that created the file had the application installed into a folder on his desktop, which could mean the rights to his desktop stick to the file. Can anyone confirm this?

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              Definately a permission issue. If you run as Adminstrator you can take ownership and change the permissions, but else you out of luck. I doubt there will be any way to circumvent this security for a non admin user or the original creator of the file.**

              xacc.ide-0.2.0 preview - Now in 100% C# goodness

              **

              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