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