Article View: borland.public.csharpbuilder.language.csharp
Article #671Re: 'File in use' error after File.Create() -- Thank you!
From: Joe Mayo
Date: Fri, 24 Sep 2004 13:10
Date: Fri, 24 Sep 2004 13:10
56 lines
2297 bytes
2297 bytes
In that case, you won't be able to open your file stream via File.Create().
Instead, instantiate it as a FileStream object:
fs = new FileStream("SomeFile3.txt", FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.ReadWrite);
Notice that I set the FileShare enum parameter to ReadWrite.
Joe
--
http://www.csharp-station.com
"John Fowler" <jfowler@pXoXl.net> wrote in message
news:4153b5ba$1@newsgroups.borland.com...
> Thanks to all who explained this.
>
> How, then, can I keep 'fs' open and write to it? Or would it be easier
> in code just to close and reopen it?
>
> Thank you.
>
> John F.
>
> Marc Rohloff [TeamB] wrote:
> > On Wed, 22 Sep 2004 22:41:08 -0600, Joe Mayo wrote:
> >
> >
> >
> >>or (which essentially means):
> >> FileStream fs = null;
> >> try
> >> {
> >> fs = File.Create("SomeFile3.txt");
> >> }
> >> finally
> >> {
> >> if (fs != null)
> >> {
> >> fs.Close();
> >> }
> >> }
> >
> >
> > The generated code is actually more like:
> >
> > FileStream fs = File.Create("SomeFile3.txt");
> > try
> > {
> > //
> > }
> > finally
> > {
> > IDisposable(fs).Dispose;
> > }
> >
Technical Details
Message-ID:
<41541cac$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.cwix.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4152442d$1@newsgroups.borland.com> <415253dc$1@newsgroups.borland.com> <8pqa860s7xbv.dlg@marcrohloff.40tude.net> <4153b5ba$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,371711e74f47af5a X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Joe Mayo" <jmayo@nospam.mayosoftware.com> Newsgroups: borland.public.csharpbuilder.language.csharp References: <4152442d$1@newsgroups.borland.com> <415253dc$1@newsgroups.borland.com> <8pqa860s7xbv.dlg@marcrohloff.40tude.net> <4153b5ba$1@newsgroups.borland.com> Subject: Re: 'File in use' error after File.Create() -- Thank you! Date: Fri, 24 Sep 2004 07:10:15 -0600 Lines: 58 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 67.176.104.159 Message-ID: <41541cac$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1096031404 67.176.104.159 (24 Sep 2004 06:10:04 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.cwix.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail