By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Jun 30 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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" wrote:
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.
Jun 30 '08 #2

P: n/a
On Sun, 29 Jun 2008 20:32:22 -0700, fyitang wrote:
>
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

Jun 30 '08 #3

P: n/a
On Jun 30, 1:26*pm, Ken Foskey <fos...@optushome.com.auwrote:
On Sun, 29 Jun 2008 20:32:22 -0700, fyitang wrote:
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
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.
Jun 30 '08 #4

P: n/a
On Jun 30, 1:06*pm, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.comwrote:
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" wrote:
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.
Jun 30 '08 #5

P: n/a

"fyitang" wrote:
On Jun 30, 1:06 pm, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.comwrote:
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" wrote:
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.

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

Jun 30 '08 #6

P: n/a
On Jun 30, 2:51*pm, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.comwrote:
"fyitang" wrote:
On Jun 30, 1:06 pm, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.comwrote:
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]
"fyitang" wrote:
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.
Jun 30 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.