Access to the path '' denied when doing fileinfo.delete()

F

fyitang

hi guys, here is the sample:

string strFileFullName = "";
try
{
FileInfo currentFile = GetOneFile("some directory");
strFileFullName = currentFile.FullName;

// do someting...

currentFile.Delete();
}
catch(exception ex)
{
savelog(ex);
File.Move(strFileFullName, "some backup folder and file name");
}

these codes are executed by a timer_click event, the timer keep
monitoring some folder, and processing the files one by one. my
question is: why i meet some exception "access to the path '' denied"
occasionally, and why these "exception file" can be moved to my backup
folder? mostly no exception happend. thanks in advance.
 
M

Morten Wennevik [C# MVP]

Hi,

Could you show is what you do to the file? FileInfo does not block file
deletion in any way and "access to path" denied would indicate you assemble
the file path in some way or other or move files. Are you using the same
file name after deleting the file? We need more information to be able to
give any better answers.
 
K

Ken Foskey

these codes are executed by a timer_click event, the timer keep
monitoring some folder, and processing the files one by one. my question
is: why i meet some exception "access to the path '' denied"
occasionally, and why these "exception file" can be moved to my backup
folder? mostly no exception happend. thanks in advance.

Is the file actually open at the time of the delete. This has happened
to me.

Ken
 
F

fyitang

Is the file actually open at the time of the delete.  This has happened
to me.

Ken

hi ken,
i guess if the file is opend, then the exception message i got would
be "The process cannot access the file '' because it is being used by
another process.". i have tried to do someting to avoid this issue.
 
F

fyitang

Hi,

Could you show is what you do to the file?  FileInfo does not block file
deletion in any way and "access to path" denied would indicate you assemble
the file path in some way or other or move files.  Are you using the same
file name after deleting the file?  We need more information to be able to
give any better answers.

--
Happy Coding!
Morten Wennevik [C# MVP]



fyitang said:
hi guys, here is the sample:
string strFileFullName = "";
try
{
  FileInfo currentFile = GetOneFile("some directory");
  strFileFullName = currentFile.FullName;
  // do someting...
  currentFile.Delete();
}
catch(exception ex)
{
  savelog(ex);
  File.Move(strFileFullName, "some backup folder and file name");
}
these codes are executed by a timer_click event, the timer keep
monitoring some folder, and processing the files one by one. my
question is: why i meet some exception "access to the path '' denied"
occasionally, and why these "exception file" can be moved to my backup
folder? mostly no exception happend. thanks in advance.- Hide quoted text -

- Show quoted text -

hi Morten,
what i do to the file can be simplified as 2 steps:
1. load the file into memory, then create an instance of one class( we
can say Sample aSample = new Sample) based on the content of the file.
2. process the instance aSample, no related to the file any more after
load finished.

and yeah, fileinfo does not block the file, so most files can be
processed successfully. and i used the same file name when backuping
the exception files, it worked.
 
M

Morten Wennevik [C# MVP]

fyitang said:
Hi,

Could you show is what you do to the file? FileInfo does not block file
deletion in any way and "access to path" denied would indicate you assemble
the file path in some way or other or move files. Are you using the same
file name after deleting the file? We need more information to be able to
give any better answers.

--
Happy Coding!
Morten Wennevik [C# MVP]



fyitang said:
hi guys, here is the sample:
string strFileFullName = "";
try
{
FileInfo currentFile = GetOneFile("some directory");
strFileFullName = currentFile.FullName;
// do someting...
currentFile.Delete();
}
catch(exception ex)
{
savelog(ex);
File.Move(strFileFullName, "some backup folder and file name");
}
these codes are executed by a timer_click event, the timer keep
monitoring some folder, and processing the files one by one. my
question is: why i meet some exception "access to the path '' denied"
occasionally, and why these "exception file" can be moved to my backup
folder? mostly no exception happend. thanks in advance.- Hide quoted text -

- Show quoted text -

hi Morten,
what i do to the file can be simplified as 2 steps:
1. load the file into memory, then create an instance of one class( we
can say Sample aSample = new Sample) based on the content of the file.
2. process the instance aSample, no related to the file any more after
load finished.

and yeah, fileinfo does not block the file, so most files can be
processed successfully. and i used the same file name when backuping
the exception files, it worked.

Hi,

This is still a bit too vague to give any good answers. If you can give
exact code snippets (remove/rename sensitive data) it would be much easier to
guess or even spot the error.

Somewhere along the line you end up with a non existant, permission
restricted or locked file or folder. Perhaps a file with spaces is causing
part of the file name to be treated as a folder. In case of web application
it is also easy to get folder access denied if you stray outside specific
folder permissions.
 
F

fyitang

fyitang said:
Hi,
Could you show is what you do to the file?  FileInfo does not block file
deletion in any way and "access to path" denied would indicate you assemble
the file path in some way or other or move files.  Are you using thesame
file name after deleting the file?  We need more information to be able to
give any better answers.
--
Happy Coding!
Morten Wennevik [C# MVP]
:
hi guys, here is the sample:
string strFileFullName = "";
try
{
  FileInfo currentFile = GetOneFile("some directory");
  strFileFullName = currentFile.FullName;
  // do someting...
  currentFile.Delete();
}
catch(exception ex)
{
  savelog(ex);
  File.Move(strFileFullName, "some backup folder and file name");
}
these codes are executed by a timer_click event, the timer keep
monitoring some folder, and processing the files one by one. my
question is: why i meet some exception "access to the path '' denied"
occasionally, and why these "exception file" can be moved to my backup
folder? mostly no exception happend. thanks in advance.- Hide quotedtext -
- Show quoted text -
hi Morten,
what i do to the file can be simplified as 2 steps:
1. load the file into memory, then create an instance of one class( we
can say Sample aSample = new Sample) based on the content of the file.
2. process the instance aSample, no related to the file any more after
load finished.
and yeah, fileinfo does not block the file, so most files can be
processed successfully. and i used the same file name when backuping
the exception files, it worked.

Hi,

This is still a bit too vague to give any good answers.  If you can give
exact code snippets (remove/rename sensitive data) it would be much easierto
guess or even spot the error.

Somewhere along the line you end up with a non existant, permission
restricted or locked file or folder.  Perhaps a file with spaces is causing
part of the file name to be treated as a folder.  In case of web application
it is also easy to get folder access denied if you stray outside specific
folder permissions.

--
Happy Coding!
Morten Wennevik [C# MVP]- Hide quoted text -

- Show quoted text -

thanks Morten, because the real process is complicated, it is hard to
abstract them, i'll try. btw, my software is a desktop application,
not web's.
 

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