473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Unable To delete the file that is created in VB.NET

i have created a directory and added the text file.while next Process,if files available,delete the file.

Throws error:
The process cannot access the file because it is being used by another process .

here attach the code for reference

If boolflag = True Then
Dim createFolderSP As DirectoryInfo = New DirectoryInfo(applnPath & "\WBRSP")
If createFolderSP.Exists Then
Dim deletefiles As IO.FileInfo() = createFolderSP.GetFiles("*.sql")
Dim intcount As Integer
For intcount = 0 To deletefiles.Length - 1
deletefiles(intcount).Delete()
Next
End If
createFolderSP.Create()
boolflag = False
End If

Dim TextFile As New StreamWriter(applnPath & "\WBRSP\" & filename)
TextFile.Write(filecontent.ToString())
TextFile.Flush()
TextFile.Close()

TextFile = Nothing
Oct 23 '08 #1
1 1367
tlhintoq
3,525 Expert 2GB
i have created a directory and added the text file.while next Process,if files available,delete the file.

Throws error:
The process cannot access the file because it is being used by another process .

here attach the code for reference

If boolflag = True Then
Dim createFolderSP As DirectoryInfo = New DirectoryInfo(applnPath & "\WBRSP")
If createFolderSP.Exists Then
Dim deletefiles As IO.FileInfo() = createFolderSP.GetFiles("*.sql")
Dim intcount As Integer
For intcount = 0 To deletefiles.Length - 1
deletefiles(intcount).Delete()
Next
End If
createFolderSP.Create()
boolflag = False
End If

Dim TextFile As New StreamWriter(applnPath & "\WBRSP\" & filename)
TextFile.Write(filecontent.ToString())
TextFile.Flush()
TextFile.Close()

TextFile = Nothing
Hi there Divisuresh,

Did you realize that nowhere in there did you actually ask a question? What part of this are you asking for help about? That you wanted to know *why* you get an error... That you want to know *what* the error means... How can you keep the program from hanging on this error... How can you detect if the file is in use before handling? How can you delete a file even if it is use by another process?

Tips for good questions

Also, it really helps if you wrap your code fragment in code tags
Oct 23 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Peter Gomis | last post by:
I have encountered a situation where I am unable to remove a .NET assembly from the GAC. The message I receive is "Assembly 'assemblyname' could not be uninstalled because it is required by other...
4
by: Brad | last post by:
Error when opening a solution with a web services project in it: "Unable to open the Web project 'myproj'. The file path 'c:\code\myservice' does not correspond to the URL...
2
by: Robert Rotstein | last post by:
I’m running an ASP.NET web service which dynamically creates a registry key, stores some values in it, then, on a subsequent call to another method in the service, attempts to delete the key. The...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
4
by: Sailor1877 via AccessMonster.com | last post by:
I've been reading all the threads about problems with LDB files but my specific problem doesn't seem to be addressed. I have a back end database on a server that I'm unable to run Compact and...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
24
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in...
5
by: maheswaran | last post by:
Hi, i have issue in FTP , i have tried with .net and also c# Note the following scenario: 1. Upload the file to FTP >than 60 MB. 2. At the time of Uploading, unplug the LAN cable (or)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.