Solved

VB.net create text file used by another process

Posted on 2014-04-15
4
903 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:murbro
[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 167 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 167 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 166 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:murbro
ID: 40006182
Thanks for the help
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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