Click here to Skip to main content
15,903,385 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Is the logged on user an administrator? Pin
Richard Deeming7-Apr-03 1:55
mveRichard Deeming7-Apr-03 1:55 
GeneralRichtextBox Control Pin
Fleischen6-Apr-03 6:57
Fleischen6-Apr-03 6:57 
GeneralVery basic question Pin
Sarvesvara (BVKS) Dasa5-Apr-03 22:47
Sarvesvara (BVKS) Dasa5-Apr-03 22:47 
GeneralRe: Very basic question Pin
J. Dunlap6-Apr-03 7:47
J. Dunlap6-Apr-03 7:47 
GeneralRe: Very basic question Pin
Sarvesvara (BVKS) Dasa6-Apr-03 21:05
Sarvesvara (BVKS) Dasa6-Apr-03 21:05 
GeneralFileSystemWatcher Pin
Zulfikar Ali4-Apr-03 8:05
Zulfikar Ali4-Apr-03 8:05 
GeneralRe: FileSystemWatcher Pin
Josep Balague8-Apr-03 4:57
professionalJosep Balague8-Apr-03 4:57 
GeneralRe: FileSystemWatcher Pin
Zulfikar Ali8-Apr-03 5:04
Zulfikar Ali8-Apr-03 5:04 
Thanks for your reply. But folders can't be sub folder in my project. Anyway i have figured out the solution. Here is the code if anybody is interested.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim strName As String
Dim strDBReject As String
Dim strParseReject As String

'Load the profile info from the setup XML file
Dim dsGetIni As New DataSet()
dsGetIni.ReadXml(Application.StartupPath & "\setup.xml")
Dim dtGetIni As DataTable = dsGetIni.Tables("Profile")
i = dtGetIni.Rows.Count

Dim objRow As DataRow()
For i = 0 To dsGetIni.Tables("Profile").Rows.Count - 1
strName = dtGetIni.Rows(i)("Name")
strDBReject = dtGetIni.Rows(i)("DBReject")
watcher(strDBReject)
strParseReject = dtGetIni.Rows(i)("ParseReject")
watcher(strParseReject)
Next
End Sub

Public Function watcher(ByVal strFolder As String)
Dim objWatcher As New System.IO.FileSystemWatcher()
'Folder to watch
objWatcher.Path = strFolder

'File extension to watch
objWatcher.Filter = "*.pdf"
'Create delegates to handle the events for the FileSystemWatcher
AddHandler objWatcher.Created, AddressOf OnFileCreated

'Exclude subdirectories from watching
objWatcher.IncludeSubdirectories = True
'Start watching folder
objWatcher.EnableRaisingEvents = True
End Function


Public Sub OnFileCreated(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
Try
'create new instance of importer
Dim FileInfo As New FileInformation(e.FullPath)
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ProcessFile), FileInfo)
Catch ex As Exception
End Try
End Sub

Private Function GetExclusiveAccess(ByVal FilePath As String) As Boolean
Try
Dim theFile As File
Dim strm As Stream = theFile.Open(FilePath, FileMode.Open)
'if we succeed, we can let it go
strm.Close()
GetExclusiveAccess = True
Catch e As Exception
GetExclusiveAccess = False
End Try
End Function

Public Sub ProcessFile(ByVal fileInfo As Object)

If Thread.CurrentThread.Name = "" Then
Thread.CurrentThread.Name = Thread.CurrentThread.GetHashCode().ToString
End If

'try to get exclusive access to the file first
Dim i As Integer
For i = 0 To 30
If GetExclusiveAccess(fileInfo.filepath) Then
Exit For
ElseIf i = 30 Then
Exit Sub
End If
Thread.Sleep(5000)
Next

Dim strFilePath As String
Dim strFileName As String
Dim strDirName As String
Dim strVendorName As String
Dim strReason As String

Dim x As Integer
Dim y As Integer

strFilePath = fileInfo.filepath
strFileName = Mid(strFilePath, InStrRev(strFilePath, "\") + 1, Len (strFilePath) - InStrRev(strFilePath, "\"))
MsgBox(strFilePath)
'Add Reject file info to the database
addtodb(strFileName, strVendorName, strFilePath, strReason)
End Sub

If anybody is interested try this code. Let me know if you have any questions. Thanks

Zulfikar Ali
GeneralHelp....... Pin
Fleischen4-Apr-03 3:40
Fleischen4-Apr-03 3:40 
GeneralRe: Help....... Pin
Nick Parker4-Apr-03 4:49
protectorNick Parker4-Apr-03 4:49 
GeneralHelp needed on Undocumented Shell "IDM_SHVIEW_NEWFOLDER". Any experts out here. Pin
Villly4-Apr-03 0:25
Villly4-Apr-03 0:25 
Generaldos commands Pin
r i s h a b h s3-Apr-03 17:22
r i s h a b h s3-Apr-03 17:22 
GeneralRe: dos commands Pin
Tim McCurdy4-Apr-03 1:35
Tim McCurdy4-Apr-03 1:35 
GeneralRe: dos commands Pin
OMalleyW19-Apr-03 7:32
OMalleyW19-Apr-03 7:32 
GeneralVB Endian Conversion Pin
mikasa3-Apr-03 10:40
mikasa3-Apr-03 10:40 
GeneralRe: VB Endian Conversion Pin
Oscar Martin3-Apr-03 21:02
Oscar Martin3-Apr-03 21:02 
GeneralRe: VB Endian Conversion Pin
J. Dunlap6-Apr-03 7:55
J. Dunlap6-Apr-03 7:55 
GeneralRe: VB Endian Conversion Pin
mikasa6-Apr-03 8:07
mikasa6-Apr-03 8:07 
GeneralRe: VB Endian Conversion Pin
J. Dunlap6-Apr-03 8:40
J. Dunlap6-Apr-03 8:40 
QuestionLazy Evaluation ternary op? Pin
eidylon3-Apr-03 9:11
eidylon3-Apr-03 9:11 
AnswerRe: Lazy Evaluation ternary op? Pin
Daniel Turini3-Apr-03 9:25
Daniel Turini3-Apr-03 9:25 
GeneralRe: Lazy Evaluation ternary op? Pin
mikasa3-Apr-03 10:44
mikasa3-Apr-03 10:44 
GeneralRe: Lazy Evaluation ternary op? Pin
Daniel Turini3-Apr-03 10:48
Daniel Turini3-Apr-03 10:48 
GeneralRe: Lazy Evaluation ternary op? Pin
mikasa3-Apr-03 10:57
mikasa3-Apr-03 10:57 
GeneralPrintPreview Question 2 Pin
Fleischen3-Apr-03 5:52
Fleischen3-Apr-03 5:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.