PC Review


Reply
Thread Tools Rate Thread

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

 
 
fyitang
Guest
Posts: n/a
 
      30th Jun 2008
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.
 
Reply With Quote
 
 
 
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      30th Jun 2008
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.
>

 
Reply With Quote
 
Ken Foskey
Guest
Posts: n/a
 
      30th Jun 2008
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

 
Reply With Quote
 
fyitang
Guest
Posts: n/a
 
      30th Jun 2008
On Jun 30, 1:26*pm, Ken Foskey <fos...@optushome.com.au> wrote:
> 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.
 
Reply With Quote
 
fyitang
Guest
Posts: n/a
 
      30th Jun 2008
On Jun 30, 1:06*pm, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.com> wrote:
> 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.
 
Reply With Quote
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      30th Jun 2008

"fyitang" wrote:

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

 
Reply With Quote
 
fyitang
Guest
Posts: n/a
 
      30th Jun 2008
On Jun 30, 2:51*pm, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.com> wrote:
> "fyitang" wrote:
> > On Jun 30, 1:06 pm, Morten Wennevik [C# MVP]
> > <MortenWenne...@hotmail.com> wrote:
> > > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An exception occurred in the OnBeforeInstall event handler of <name> Access to the path <path> is denied. Andrzej Lipski Microsoft Dot NET 0 5th Oct 2007 04:24 PM
Access to the path is denied. Santosh Microsoft ASP .NET 1 16th Oct 2006 01:32 PM
Access to the path .... is denied j_stus@hotmail.com Microsoft ASP .NET 3 23rd May 2006 04:10 PM
delete file: Access to the path 'X' is denied wo20051223@yahoo.com Microsoft C# .NET 5 6th Mar 2006 08:07 PM
Access to the path is denied Theerachet Pratoommanee Microsoft Dot NET 1 30th Dec 2003 09:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:41 PM.