🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #666

Re: 'File in use' error after File.Create()

#666
From: Joe Mayo
Date: Thu, 23 Sep 2004 04:41
44 lines
1897 bytes
Hi John,

File.Create() opens a file stream, which you must close before accessing the
file via a second stream.  Here are a couple options:

  using (File.Create("SomeFile3.txt")){}

or (which essentially means):

  FileStream fs = null;

  try
  {
   fs = File.Create("SomeFile3.txt");
  }
  finally
  {
   if (fs != null)
   {
    fs.Close();
   }
  }

Joe
-- 
http://www.csharp-station.com

"John Fowler" <jfowler@pXoXl.net> wrote in message
news:4152442d$1@newsgroups.borland.com...
> Hi!
> I'm using the following to create a file (if it's not already present)
> to write strings to. When I do so, I get an error stating that the file
> cannot be accessed because it's in use by another process.
>
> string saveFile = @"..\..\myStringFile.txt";
> File.Create( saveFile );
> myFlexGrid.SaveGrid( saveFile, FileFormatEnum.TextComma );
>
>
> What is that process and how do I fix it?
>
> Thank you for any and all help.
>
> John F.
Technical Details
Message-ID: <415253dc$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4152442d$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>
Subject: Re: 'File in use' error after File.Create()
Date: Wed, 22 Sep 2004 22:41:08 -0600
Lines: 46
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: <415253dc$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1095914460 67.176.104.159 (22 Sep 2004 21:41:00 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail