file in use
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
8 posts
Page 1 of 1
hello,
can anyone help me with this part also
what are we doing wrong?
thanks
can anyone help me with this part also
Code: Select all
the file stays in use so i can't delete it Dim Files As String() = Directory.GetFiles("c:\", "*.txt")
For Each sFile As String In Files
Dim fi As New FileInfo(sFile)
Dim myFileStream As New System.IO.FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)
Dim myReader As New System.IO.StreamReader(myFileStream)
Dim sFileContents As String = myReader.ReadToEnd()
myReader.Close()
myFileStream.Close()
what are we doing wrong?
thanks
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
I can't recreate your error using vs2013.
Haven't you opened file in other program? And can you please give some more info. Like on what line does exception occurs.
Edit: you can change
Haven't you opened file in other program? And can you please give some more info. Like on what line does exception occurs.
Edit: you can change
Code: Select all
to
Dim fi As New FileInfo(sFile)
Dim myFileStream As New System.IO.FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)
Dim myReader As New System.IO.StreamReader(myFileStream)
Code: Select all
As StreamReader also can take file path with name as argument. Then myFileStream.Close() is also not needed.Dim fi As New FileInfo(sFile)
Dim myReader As New System.IO.StreamReader(fi.FullName)
Last edited by Ffenixw0rks on Mon Jun 09, 2014 5:51 pm, edited 2 times in total.
Why do you use the "FileStream" and "StreamReader" to read text based files, and not the built-in functions?
You can find me on Facebook or on Skype mihai_92b
Shim wrote:close your visual studio or close the project then delete it.#Shim :lol: because i need to delete it when i run the app itself
Ffenixw0rks wrote:I can't recreate your error using vs2013.#Ffenixw0rks no this is the only app that use the file
Haven't you opened file in other program? And can you please give some more info. Like on what line does exception occurs.
Edit: you can changeCode: Select alltoDim fi As New FileInfo(sFile) Dim myFileStream As New System.IO.FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read) Dim myReader As New System.IO.StreamReader(myFileStream)
Code: Select allAs StreamReader also can take file path with name as argument. Then myFileStream.Close() is also not needed.Dim fi As New FileInfo(sFile) Dim myReader As New System.IO.StreamReader(fi.FullName)
changed it but same error
Access to the path 'c:\oft.txt' is denied.
XTechVB wrote:Why do you use the "FileStream" and "StreamReader" to read text based files, and not the built-in functions?#XTechVB no idea whats the different between them?
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
Dummy1912 wrote: #XTechVB no idea whats the different between them?Well, the built-in finctions like IO.File.ReadAllText(), IO.File.ReadAllLines() were specifically created to avoid this type of problems you are having.
That's why they close the files automatically, making them available for other uses.
You can find me on Facebook or on Skype mihai_92b
#Dummy1912 if error will still occur - try to logout and log in from Windows.
Another way is to use Unlocker to see what app is using file at the moment. cooll;
Another way is to use Unlocker to see what app is using file at the moment. cooll;
thank you guys
working now
weird :lol:
working now
weird :lol:
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
8 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023