Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
| Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2008, 03:47 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: West Palm Beach, Florida, USA.
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Default [Resolved] Error: File used by another process

I have a sub that creates a text (work file) like this:

Code:
Public Sub CreateTextFile()
  RelativePath = String.Format("\{0:yyyyMMdd_HHmmss}.txt", Date.Now)
  IO.File.Create(("\\VGIWPW03-SQL3\c$\temp" & RelativePath))
End Sub
Then I have a sub that adds content to the created text file, like this:

Code:
Dim fieldterminator As Char = ControlChars.Tab
            Dim rowterminator As Char = ControlChars.CrLf
            Dim absolutePath As String = "\\VGIWPW03-SQL3\c$\temp" & RelativePath
            Dim content As String = ticket_date _
                                     & fieldterminator _
                                     & job _
                                     & fieldterminator _
                                     & job_phase _
                                     & fieldterminator _
                                     & tons _
                                     & fieldterminator _
                                     & qty_received _
                                     & fieldterminator _
                                     & qty_used _
                                     & fieldterminator _
                                     & qty_wasted _
                                     & fieldterminator _
                                     & plant
   IO.File.AppendAllText(absolutePath, content + Environment.NewLine)
I get an error on the Io.File>AppendAllText saying:

The process cannot access the file xxxxx because it is being used by another process..
 
Old February 16th, 2008, 05:56 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The File.Create() function returns a FileStream object. You need to close that before the file will be available for writing with AppendAllText().

e.g.

Dim fs As IO.FileStream = IO.File.Create(("\\VGIWPW03-SQL3\c$\temp" & RelativePath))
fs.Close()

Alternatively, create the file and write the text in one go by calling File.WriteAllText()

/- Sam Judson : Wrox Technical Editor -/
 
Old February 18th, 2008, 09:20 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: West Palm Beach, Florida, USA.
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Default

It worked, thank you.....





Similar Threads
Thread Thread Starter Forum Replies Last Post
[resolved] File is 'locked'? after printing. janama .NET Framework 2.0 4 April 20th, 2008 01:03 AM
[Resolved] Error calling a sp - parameter error snufse .NET Framework 2.0 2 February 12th, 2008 04:46 PM
(Resolved) TableAdapter Error ksamuel Pro Visual Basic 2005 1 January 16th, 2008 01:03 PM
file error ...being used by another process rreynolds Pro VB.NET 2002/2003 6 January 11th, 2005 11:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.