From: AMP on 17 Jan 2010 09:40 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 17 Jan 2010 10:45 "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 17 Jan 2010 11:31 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 17 Jan 2010 12:46 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 17 Jan 2010 16:05 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
|
Next
|
Last
Pages: 1 2 Prev: WinForm - Color difference between windows XP and Windows 7 Next: RDA (remote data access) |