System.IO.FileInfo.Delete()

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

I have a problem with System.IO.FileInfo.

FileInfo fi = new FileInfo("testFile.txt");
Logger.Write(String.Format("isExist: {0}", fi.Exist() ));

if (fi.Exist())
fi.Delete();

The value of fi.Exist is always True, but sometimes I cannot delete the
textfile. I am not getting any errors, but my service app just stops by
itself.

Why is this ?? Is it the textfile is being used by another process ? But I
am not getting any error messages at all.

Any help is appreciated.

Thanks in advance

regards,
Andrew
 
I have a problem with System.IO.FileInfo.

FileInfo fi = new FileInfo("testFile.txt");
Logger.Write(String.Format("isExist: {0}", fi.Exist() ));

if (fi.Exist())
fi.Delete();

The value of fi.Exist is always True, but sometimes I cannot delete the
textfile. I am not getting any errors, but my service app just stops by
itself.

Why is this ?? Is it the textfile is being used by another process ? But I
am not getting any error messages at all.

Any help is appreciated.

Framework version?

Have you wrapped your call to Delete() in a try/catch block and attempted to
log any errors?
 
I've wrapped, and I've got no errors at all.
Doesn't makes any sense doesn't it ?

Could it be an System.IO issue ?? eg. process cannot access the file "xx"
because it is being used by another process issue ?? If so, then how do you
suggest I detect if another process is indeed using the file ??
 
I've wrapped, and I've got no errors at all.
Doesn't makes any sense doesn't it ?

Could it be an System.IO issue ?? eg. process cannot access the file "xx"
because it is being used by another process issue ?? If so, then how do
you
suggest I detect if another process is indeed using the file ??

You still haven't told us WHAT VERSION OF THE .NET FRAMEWORK YOU'RE USING.
(It may be important; there may be known bugs with certain versions.)

And I have code that creates (and overwrites) PDF files and if someone
happens to have the PDF open that I want to overwrite, it creates a new file
with [1] on the end. I did this by simply trapping the error you're trying
to trap and it works great. So there's something else going on with your
setup....
 
Thanks for your reply.
I'm using Framework v2.0 and VisualStudio 2005.

Is there a way I can check if another resource is using the said file,
before I try to delete the file.

Thanks in advance

regards,
Andrew


Jeff Johnson said:
I've wrapped, and I've got no errors at all.
Doesn't makes any sense doesn't it ?

Could it be an System.IO issue ?? eg. process cannot access the file "xx"
because it is being used by another process issue ?? If so, then how do
you
suggest I detect if another process is indeed using the file ??

You still haven't told us WHAT VERSION OF THE .NET FRAMEWORK YOU'RE USING.
(It may be important; there may be known bugs with certain versions.)

And I have code that creates (and overwrites) PDF files and if someone
happens to have the PDF open that I want to overwrite, it creates a new file
with [1] on the end. I did this by simply trapping the error you're trying
to trap and it works great. So there's something else going on with your
setup....
 
Back
Top