Access is denied - WINDOWS App!

G

Guest

I have been chasing what should be a simple problem for a day or two now. I
have done the google thing, but all the problems listed (at least so far)
have been problems with web applications.

My application is a WINDOWS app, and during the run I create a directory
called "CURRENT FLIGHT", and inside that directory I create several other
directories and files inside those. I update those files during the flight
phases. After the flight ends, I need to extract information from a XML file
in one of those sub-directories, create a new directory with our standard
name, and "move" all the directories and files from the current directory
into the new one. During shutdown this all works perfectly. HOWEVER, there
are events during the flights that I respond to, and one of those needs to do
the above process of creating a new directory, and move the files while in
flight, then continue processing. When I try this I get IO.Exception stating
"Access to the path <current flight directory> is denied". I created it, I
have been updating files in directories under it, but now I can't access it?
Hmmm....I am obviously missing something. Can anyone tell me what?

By the way I DO make sure all the files that I have been writing to inside
that directory are closed before I do any of this processing.

Thanks.
WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
 
J

Jon Skeet [C# MVP]

WhiteWizard said:
I have been chasing what should be a simple problem for a day or two now. I
have done the google thing, but all the problems listed (at least so far)
have been problems with web applications.

Can you post a short but complete program which demonstrates the
problem?

Jon
 
G

Guest

The program is pretty long, but here is the relevant code:

This is what I use to create the directories (modified):
public void CreateDirectories(EDSCommon.StayaliveClass tempStayaliveMessage)
{
if (Directory.Exists(rmmDriveLetter))
{
flightIdDir = rmmDriveLetter + "CURRENT FLIGHT";
rmmInitialized = true;
}
// Define the different directories on the RMM.
eventDir = flightIdDir + @"\Event Data";
engineDir = flightIdDir + @"\Engine Data";
engTrendDir = flightIdDir + @"\Trend Data";
lessTrendDir = flightIdDir + @"\LESS Data";
formsDir = flightIdDir + @"\Forms Data";

// If there is an RMM detected then create the directories on it.
if(rmmInitialized)
{
DirectoryInfo di = Directory.CreateDirectory(flightIdDir);
di = Directory.CreateDirectory(eventDir);
di = Directory.CreateDirectory(engineDir);
di = Directory.CreateDirectory(engTrendDir);
di = Directory.CreateDirectory(lessTrendDir);
di = Directory.CreateDirectory(formsDir);
}
}

Here is the code where the problem occurs. Note that this same method works
during shutdown, just not during the regular processing:

private void FinalizeRMMCurrentFlight()
{
if (rmmInitialized)
{
if (Directory.Exists(rmmDriveLetter + @"\Current Flight"))
{
try
{
DirectoryInfo di = new DirectoryInfo(rmmDriveLetter + @"\Current
Flight" + @"\Forms Data");
FileDirectoryIdInfo idInfo;
idInfo = GetFileDirectoryIdInfo(di);
string rmmTailNumber = idInfo.TailNumber;
DateTime rmmFlightDate = idInfo.TakeoffTime;

Directory.Move(rmmDriveLetter + @"\Current Flight",
rmmDriveLetter + rmmTailNumber
+ rmmFlightDate.Year.ToString("0#") +
rmmFlightDate.Month.ToString("0#")
+ rmmFlightDate.Day.ToString("0#") + "_" +
rmmFlightDate.Hour.ToString("0#")
+ rmmFlightDate.Minute.ToString("0#") +
rmmFlightDate.Second.ToString("0#") + "_1");
}
catch (FileNotFoundException exp)
{
/* What we have here is a failure to communicate - The FSR has
not been writen yet so can't be copied
so we just swallow this exception, continue processing, and
this directory will NOT be displayed
on the RMMCopyContol
*/
}
catch (Exception exp)
{
/* For testing only, not to be in production version */
MessageBox.Show(exp.ToString());
}
}
}
}

During the processing of the app, I update files in all of the
sub-directories, but I have a close method that closes all the files before I
go through the FinalizeRMM...method above.

HTH. Any thoughts?

WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
 
P

PS

WhiteWizard said:
The program is pretty long, but here is the relevant code:

This is what I use to create the directories (modified):
public void CreateDirectories(EDSCommon.StayaliveClass
tempStayaliveMessage)
{
if (Directory.Exists(rmmDriveLetter))
{
flightIdDir = rmmDriveLetter + "CURRENT FLIGHT";

Where is your \ seperator like you have in your Finalize method?

PS
 
M

manstein

WhiteWizard,

First off, Check the event viewer and see if there is a related
Error entry under applications. What you might find is that ASPNET
does not have write access to the directories in question. If not, and
there is an event log, then you have something to start with :) Now,
since you are creating these directories, you might have to set
permissions on a Parent directory higher up that allows the account
under which your program is running to have full control and propagate
the changes to subdirectories. If this is a network share, then you
have to set these permissions on the share as well. goto directory
properties -> sharing -> permissions.
 
G

Guest

Good eye!

I tried changing that, thinking it might be that it was looking for the
wrong directory, but that had no effect. Actually had I thought about it,
the CURRENT FLIGHT directory was being created correctly AND is being
processed correctly during shutdown, but just not "in flight".

Thanks for the response though!

WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top