File.Delete()

G

Guest

Hello

Consider the following code

Stream s = File.Create(filename)
XmlTextWriter writer = new XmlTextWriter(s,encoding)

// write some elements ..

writer.Flush()
writer.Close()
s.Close()

After processing the file, I have to delete it
File.Delete(filename)

However, this throws an IOException (file in use probably). I'm almost sure that the stream or the writer still has a lock on the file. How can I force the file deletion

thx
Pieter
 
N

Nico Debeuckelaere

Maybe by also putting writer.Dispose()

Regards,

--

Nico Debeuckelaere

ND-Sign BVBA (Microsoft Certified Partner since 2004)
URL: http://www.nd-sign.com
== ND-Sign, Designed for you ==
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Pieter said:
Hello,

Consider the following code:

Stream s = File.Create(filename);
XmlTextWriter writer = new XmlTextWriter(s,encoding);

// write some elements ...

writer.Flush();
writer.Close();
s.Close();

After processing the file, I have to delete it:
File.Delete(filename);

However, this throws an IOException (file in use probably). I'm almost
sure that the stream or the writer still has a lock on the file. How can I
force the file deletion?
 

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