Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.net create text file used by another process

Posted on 2014-04-15
4
Medium Priority
?
930 Views
Last Modified: 2014-04-17
Hi
I use the following line to create a text file.If I run the application again it says that it is being
used by another process. How do I ensure that this doesn't happen

     oWriter = New System.IO.StreamWriter(SYS_FOLDER & "\Customer_Invoice_Email_Queue.txt")
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 668 total points
ID: 40001050
make sure you will close the stremwriter oWriter.Close()




Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True)
file.WriteLine("Here is the first string.")
file.Close()
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 668 total points
ID: 40001075
on top, use USING statement:
http://msdn.microsoft.com/en-us/library/htd05whh.aspx
Using file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True)
file.WriteLine("Here is the first string.")
file.Close() 
End Using 

Open in new window

0
 
LVL 19

Assisted Solution

by:Shahan Ayyub
Shahan Ayyub earned 664 total points
ID: 40003775
There are couple of ways to handle it:

1) Use `using` block as suggested by other users
2) Wrap code inside Try..Catch..Finally block, and in finally block `Close` the file.
3) You should wrap it into Try..Catch..Finally block it is possible that the file you are trying to modify is open in another application. So you can not do anything except waiting to release the file by another application.

First two point will help you to handle the case if your application is opening a file and not releasing/closing it. The last point will help if the file is in use by another application.

Hope it helps!
0
 

Author Closing Comment

by:Murray Brown
ID: 40006182
Thanks for the help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question