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. Access is denied

Access is denied

Scheduled Pinned Locked Moved C#
csharpvisual-studiodebugginghelpquestion
2 Posts 2 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
    jon 80
    wrote on last edited by
    #1

    I'm getting the following error with VS2010 (still training), and, I can create a text file within this directory and as a matter of fact the executable is being created, so why is this error being displayed? :confused:

    Warning GettingStarted Could not create output directory 'C:\Documents and Settings\Jon\My Documents\Visual Studio 2010\Projects\Training\CreateEventLog\GettingStarted\GettingStarted\bin\Debug\'. Access is denied.
    1

    Jon

    F 1 Reply Last reply
    0
    • J jon 80

      I'm getting the following error with VS2010 (still training), and, I can create a text file within this directory and as a matter of fact the executable is being created, so why is this error being displayed? :confused:

      Warning GettingStarted Could not create output directory 'C:\Documents and Settings\Jon\My Documents\Visual Studio 2010\Projects\Training\CreateEventLog\GettingStarted\GettingStarted\bin\Debug\'. Access is denied.
      1

      Jon

      F Offline
      F Offline
      fjdiewornncalwe
      wrote on last edited by
      #2

      It appears that your application which resides in the ...\bin\debug directory is attempting to create the folder in which it resides. The key is in your error message. Cout not create output **directory**. My suspicion is that you are using Directory.CreateDirectory instead of File.Create. If you are using the sample from MSDN (http://msdn.microsoft.com/en-us/library/as2f1fez.aspx[^]) The safe way to do this is to always check if an object already exists before trying to create it.

      if(!Directory.Exists "your directory path"))
      {
      Directory.CreateDirectory("your path");
      }

      // There are multiple ways to do this part...
      // 1 way - This way will open the file if it exist, but create a new one if it doesn't.
      FileStream fs;
      if(!File.Exists("your file path"))
      {
      fs = File.Create("your file path");
      }
      else
      {
      fs = new FileStream("your file path", FileMode.Open);
      }

      // A 2nd way - This one will delete the existing file and let you start off with a new file.
      if(File.Exists("your file path"))
      {
      File.Delete("your file path");
      }

      using(FileStream fs = File.Create("your file path"))
      {
      ... Write stuff to the file here
      }

      using (FileStream fs = File.OpenRead(path))
      {
      ... Read the contents of the file here
      }

      This MSDN FileStream[^] library article is a very good one to learn from.

      I wasn't, now I am, then I won't be anymore.

      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