Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 15th, 2009, 05:04 AM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default Deleting a file

Have this code..
publicbool Method()
{
string fileName = Guid.NewGuid().ToString();//generate a unique filename
try
{
XmlDocument doc = newXmlDocument();

doc.LoadXml(xmlString);
doc.Save(fileName);
doc =
null;
Reader =
newXmlTextReader(fileName);//need to modify this for web application implementation
.................
}
catch (UnauthorizedAccessException AccessEx)
{
throw AccessEx;
}
catch (Exception Ex)
{
throw Ex;
}
finally
{
File.Delete(fileName);//this throws an exception that says
}

}

Unhandled Exception: System.IO.IOException: The process cannot access the file '
....................\bin\Debug\b4c2f977-b8a0-482c-9edd-f998030eac44' because it is being
used by another process.

I tried sleeping the thread for 10 seconds before calling delete but to no avail.

Let me know what am I doing wrong here..


__________________
\"Dont you ever give up!\"
 
Old April 15th, 2009, 07:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi..

Are you closing the file anywhere???
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old April 15th, 2009, 05:32 PM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi aldwinenriquez

As I understand it File.Delete simply calls the Win32 DeleteFile API
Also check if an ActiveX component your using has a handle on the file
Try this:

Code:
}
File.Delete(fileName)
Thread.Sleep(1000)
}
You need to remove the file from the array aswell.

 
Old April 15th, 2009, 08:24 PM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default

My mistake, I forgot to close the textreader that was using that stream..:-)

Thanks guys..
__________________
\"Dont you ever give up!\"





Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting problems jackiew General .NET 0 August 17th, 2006 01:41 PM
deleting a file after it is been uploaded yts007 Dreamweaver (all versions) 1 August 16th, 2006 01:05 AM
Deleting file after ftp download otarboy Pro VB 6 0 September 27th, 2004 03:58 AM
Cookie deleting value andybeh ASP.NET 1.0 and 1.1 Basics 0 June 4th, 2004 12:24 AM
Deleting duplicates prabodh_mishra SQL Server 2000 3 September 23rd, 2003 09:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.