From: AMP on
Hello,
I have:
writer = XmlWriter.Create("mike.xml",settings);
// ......Do Some stuff. This works writes an xml file.
// Then I try to close it
writer.Flush();
writer.Close();
//But I get an error saying I cant open it, its being used
FileStream fs = new FileStream("mike.xml", FileMode.Open);
....More stuff

What am I missing?
Thanks
From: Mark Rae [MVP] on
"AMP" <ampeloso(a)gmail.com> wrote in message
news:4ffc568b-828d-4c40-b5a2-1239b0928c91(a)k19g2000yqc.googlegroups.com...

> What am I missing?

Works fine for me... What is the value of "settings"...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

From: Family Tree Mike on
On 1/17/2010 9:40 AM, AMP wrote:
> Hello,
> I have:
> writer = XmlWriter.Create("mike.xml",settings);
> // ......Do Some stuff. This works writes an xml file.
> // Then I try to close it
> writer.Flush();
> writer.Close();
> //But I get an error saying I cant open it, its being used
> FileStream fs = new FileStream("mike.xml", FileMode.Open);
> ....More stuff
>
> What am I missing?
> Thanks

Try:

using (XmlWriter writer = XmlWriter.Create("mike.xml", settings))
{
// do stuff...
writer.Flush();
writer.Close();
}

using (FileStream fs = new FileStream("mike.xml", FileMode.Open))
{
}

--
Mike
From: Peter Duniho on
AMP wrote:
> Hello,
> I have:
> writer = XmlWriter.Create("mike.xml",settings);
> // ......Do Some stuff. This works writes an xml file.
> // Then I try to close it
> writer.Flush();
> writer.Close();
> //But I get an error saying I cant open it, its being used
> FileStream fs = new FileStream("mike.xml", FileMode.Open);
> ....More stuff
>
> What am I missing?

As Mark says, the code you posted as-is works fine. So obviously the
problem is related to code you didn't post.

You should post a concise-but-complete code example that reliably
demonstrates the problem. Only with that can any of us confidently say
exactly what the problem is.

Given your stated error, most likely you have failed to properly close
the original file somehow. But there's no way to know where that
particular problem is if you don't show the relevant code.

Pete
From: Arne Vajhøj on
On 17-01-2010 09:40, AMP wrote:
> I have:
> writer = XmlWriter.Create("mike.xml",settings);
> // ......Do Some stuff. This works writes an xml file.
> // Then I try to close it
> writer.Flush();
> writer.Close();
> //But I get an error saying I cant open it, its being used
> FileStream fs = new FileStream("mike.xml", FileMode.Open);
> ....More stuff
>
> What am I missing?

Are you sure that Close actually gets called?

Is the same file being opened by some other code within your app?

Arne