Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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..
Reply With Quote
  #2 (permalink)  
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 -/
Reply With Quote
  #3 (permalink)  
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.....

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:13 PM.


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