Japskunk72
Programmer
I found some code to watch files on my hard drive for changes. I want to be able to save files and have them auto organize if they are not in the right place. i can handle that code, but i am having file accesssing rights issues. for instance I have been testing the program by making a new Document from Microsoft Word. when i go to save as: and tell it to go in the specified directory that the file watch is watching, it doesnt detect any new files created. it will give be an error through my try and catch. the error is:
System.IO.IOException: The process cannot access the file "c:\documents and settings\username\desktop\SomeDoc.doc" because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at FileWatcherMain.Form1.objFSW_Created(Object sender, FileSystemEventArgs e)
My code is this :
Imports System.IO
Imports System.IO.IOException
Public Class Form1
Inherits System.Windows.Forms.Form
Protected WithEvents objFSW As New FileSystemWatcher()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objFSW.Path = "c:\"
objFSW.EnableRaisingEvents = True
objFSW.Filter = "*.*"
objFSW.IncludeSubdirectories = True
End Sub
Private Sub objFSW_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles objFSW.Created
Try
Dim objStream As New FileStream(e.FullPath, FileMode.OpenOrCreate)
Dim objRead As New StreamReader(objStream)
LSTNew.Items.Add(e.FullPath)
objStream.Close()
Catch Errr As System.IO.IOException
Console.WriteLine(Errr)
End Try
End Sub
End Class
all i have on the form is a lstbox to visualy update named LSTNew
Is there a way to read the file attributes without having to open the file and cause it to be used? I am new to VB.Net and had problems with ReaddirectoryChangesW in VB6.0 thats why i am trying to take this new route. any info would be very helpful
Thanks in advanced
System.IO.IOException: The process cannot access the file "c:\documents and settings\username\desktop\SomeDoc.doc" because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at FileWatcherMain.Form1.objFSW_Created(Object sender, FileSystemEventArgs e)
My code is this :
Imports System.IO
Imports System.IO.IOException
Public Class Form1
Inherits System.Windows.Forms.Form
Protected WithEvents objFSW As New FileSystemWatcher()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objFSW.Path = "c:\"
objFSW.EnableRaisingEvents = True
objFSW.Filter = "*.*"
objFSW.IncludeSubdirectories = True
End Sub
Private Sub objFSW_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles objFSW.Created
Try
Dim objStream As New FileStream(e.FullPath, FileMode.OpenOrCreate)
Dim objRead As New StreamReader(objStream)
LSTNew.Items.Add(e.FullPath)
objStream.Close()
Catch Errr As System.IO.IOException
Console.WriteLine(Errr)
End Try
End Sub
End Class
all i have on the form is a lstbox to visualy update named LSTNew
Is there a way to read the file attributes without having to open the file and cause it to be used? I am new to VB.Net and had problems with ReaddirectoryChangesW in VB6.0 thats why i am trying to take this new route. any info would be very helpful
Thanks in advanced