Click here to Skip to main content
15,908,111 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Code to Solve Texas Holdem Poker Hand Pin
Dave Kreskowiak11-Aug-09 9:04
mveDave Kreskowiak11-Aug-09 9:04 
QuestionSending emails to myself from 'contact us' page Pin
chana gibber11-Aug-09 8:07
chana gibber11-Aug-09 8:07 
AnswerRe: Sending emails to myself from 'contact us' page Pin
nlarson1111-Aug-09 8:17
nlarson1111-Aug-09 8:17 
GeneralRe: Sending emails to myself from 'contact us' page Pin
Pandey Vijay Kumar S.24-Sep-09 17:50
Pandey Vijay Kumar S.24-Sep-09 17:50 
GeneralRe: Sending emails to myself from 'contact us' page Pin
Pandey Vijay Kumar S.24-Sep-09 17:50
Pandey Vijay Kumar S.24-Sep-09 17:50 
QuestionGet IP Address and username using FileSystemWatcher in vb.net2.0 Pin
Pandey Vijay Kumar S.11-Aug-09 2:53
Pandey Vijay Kumar S.11-Aug-09 2:53 
AnswerRe: Get IP Address and username using FileSystemWatcher in vb.net2.0 Pin
Dave Kreskowiak11-Aug-09 4:05
mveDave Kreskowiak11-Aug-09 4:05 
GeneralRe: Get IP Address and username using FileSystemWatcher in vb.net2.0 Pin
Pandey Vijay Kumar S.11-Aug-09 17:53
Pandey Vijay Kumar S.11-Aug-09 17:53 
Thanks for Reply

Imports System.IO
Imports System.Configuration
Imports System.Net.IPAddress
Imports System.Net.Dns
Imports FSWatcher.SystemInfo
Imports System.Windows.Forms
Imports System.Net
Imports System.DirectoryServices
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.Net.NetworkInformation
Imports System.Threading

Public Class Form1
    Inherits System.Windows.Forms.Form
    Public workgroup As String
    Public WGroup As String = ""
    'Public WithEvents Nc As NetComp
    Public CompNode As New TreeNode(), CompInfo(1) As String
    Private Delegate Sub updatetextbox(ByVal newLabel As String)
    'Create the Advanced File System Watcher
    Private WithEvents myfswFileWatcher As AdvancedFileSystemWatcher
    Dim ip1 As String




#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        'I got tired of dealing with cross thread errors, so I am ignoreing them, not the way to code here so you should do it correctly
        'I did it so I caould get the code running as soon as possible.
        Control.CheckForIllegalCrossThreadCalls = False

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents txtFolderToWatch As System.Windows.Forms.TextBox
    Friend WithEvents btnBrowse As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnStart As System.Windows.Forms.Button
    Friend WithEvents btnStop As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents txtFileEvents As System.Windows.Forms.TextBox
    Friend WithEvents chkSubFolders As System.Windows.Forms.CheckBox
    Friend WithEvents fbdBrowserFolders As System.Windows.Forms.FolderBrowserDialog
    Friend WithEvents chkSilentMode As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.txtFileEvents = New System.Windows.Forms.TextBox
        Me.txtFolderToWatch = New System.Windows.Forms.TextBox
        Me.btnBrowse = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnStart = New System.Windows.Forms.Button
        Me.btnStop = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.chkSubFolders = New System.Windows.Forms.CheckBox
        Me.fbdBrowserFolders = New System.Windows.Forms.FolderBrowserDialog
        Me.chkSilentMode = New System.Windows.Forms.CheckBox
        Me.SuspendLayout()
        '
        'txtFileEvents
        '
        Me.txtFileEvents.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.txtFileEvents.Location = New System.Drawing.Point(0, 64)
        Me.txtFileEvents.Multiline = True
        Me.txtFileEvents.Name = "txtFileEvents"
        Me.txtFileEvents.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.txtFileEvents.Size = New System.Drawing.Size(803, 536)
        Me.txtFileEvents.TabIndex = 0
        '
        'txtFolderToWatch
        '
        Me.txtFolderToWatch.Location = New System.Drawing.Point(0, 8)
        Me.txtFolderToWatch.Name = "txtFolderToWatch"
        Me.txtFolderToWatch.Size = New System.Drawing.Size(320, 20)
        Me.txtFolderToWatch.TabIndex = 1
        '
        'btnBrowse
        '
        Me.btnBrowse.Location = New System.Drawing.Point(328, 8)
        Me.btnBrowse.Name = "btnBrowse"
        Me.btnBrowse.Size = New System.Drawing.Size(24, 16)
        Me.btnBrowse.TabIndex = 2
        Me.btnBrowse.Text = "..."
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(360, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(80, 16)
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "Browse Folder"
        '
        'btnStart
        '
        Me.btnStart.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnStart.Location = New System.Drawing.Point(809, 72)
        Me.btnStart.Name = "btnStart"
        Me.btnStart.Size = New System.Drawing.Size(80, 32)
        Me.btnStart.TabIndex = 4
        Me.btnStart.Text = "Start Watching"
        '
        'btnStop
        '
        Me.btnStop.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnStop.Location = New System.Drawing.Point(809, 120)
        Me.btnStop.Name = "btnStop"
        Me.btnStop.Size = New System.Drawing.Size(80, 32)
        Me.btnStop.TabIndex = 5
        Me.btnStop.Text = "Stop Watching"
        '
        'btnExit
        '
        Me.btnExit.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnExit.Location = New System.Drawing.Point(817, 576)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(75, 23)
        Me.btnExit.TabIndex = 6
        Me.btnExit.Text = "Exit"
        '
        'chkSubFolders
        '
        Me.chkSubFolders.Location = New System.Drawing.Point(448, 0)
        Me.chkSubFolders.Name = "chkSubFolders"
        Me.chkSubFolders.Size = New System.Drawing.Size(128, 32)
        Me.chkSubFolders.TabIndex = 7
        Me.chkSubFolders.Text = "Include SubFolders?"
        '
        'chkSilentMode
        '
        Me.chkSilentMode.Location = New System.Drawing.Point(152, 40)
        Me.chkSilentMode.Name = "chkSilentMode"
        Me.chkSilentMode.Size = New System.Drawing.Size(240, 24)
        Me.chkSilentMode.TabIndex = 8
        Me.chkSilentMode.Text = "Silent Mode to Log File"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(897, 605)
        Me.Controls.Add(Me.chkSilentMode)
        Me.Controls.Add(Me.chkSubFolders)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnStop)
        Me.Controls.Add(Me.btnStart)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnBrowse)
        Me.Controls.Add(Me.txtFolderToWatch)
        Me.Controls.Add(Me.txtFileEvents)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "Form1"
        Me.Text = "Folder Watcher"
        Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Try
            btnStop.Enabled = False
            With System.Configuration.ConfigurationSettings.AppSettings
                txtFolderToWatch.Text = .Get("PathToWatch")
                chkSubFolders.Checked = CType(.Get("IncludeSubFolders"), Boolean)
                chkSilentMode.Checked = CType(.Get("SilentMode"), Boolean)
            End With


        Catch ex As Exception
            Throw ex
        End Try

        GetIPDomain(ip1)
    End Sub


    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        'fbdBrowserFolders.RootFolder = Environment.SpecialFolder.Personal
        Try
            fbdBrowserFolders.ShowDialog()
            txtFolderToWatch.Text = fbdBrowserFolders.SelectedPath.ToString
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Try
            'call the sub that will create and start the AdvancedFileSystemWatcher
            StartFileSystemWatcher()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        Try
            'Stop the AdvancedFileSystemWatcher from raising events.
            StopFileSystemWatcher()
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Private Sub StartFileSystemWatcher()
        Try
            If txtFolderToWatch.Text.Trim.Length > 0 Then
                'Create a new Advanced File System Watcher and set the network scan interval
                myfswFileWatcher = New AdvancedFileSystemWatcher(5000)
                'Add the handlers to handle the filesystemwatcher events
                AddHandler myfswFileWatcher.Created, AddressOf OnCreated
                AddHandler myfswFileWatcher.Changed, AddressOf OnChanged
                AddHandler myfswFileWatcher.Deleted, AddressOf Ondeleted
                AddHandler myfswFileWatcher.Renamed, AddressOf OnRenamed
                'set the filewatcher path
                myfswFileWatcher.Path = txtFolderToWatch.Text
                'determine if the user wants to watch sub folders or not
                If chkSubFolders.Checked Then
                    myfswFileWatcher.IncludeSubdirectories = True
                Else
                    myfswFileWatcher.IncludeSubdirectories = False
                End If

                'Start the filewatcher watching for files.
                myfswFileWatcher.EnableRaisingEvents = True
                'set the GUI to reflect the fact the file system watcher is running
                chkSubFolders.Enabled = False
                btnStop.Enabled = True
                btnStart.Enabled = False
            Else
                MessageBox.Show("Folder to watch is not Set", "No Folder Set", MessageBoxButtons.OK)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub StopFileSystemWatcher()

        Try
            'Stop the file system watcher from raising events
            myfswFileWatcher.EnableRaisingEvents = False
            'set the GUI to reflect that the file system watcher is no longer watching the folders.
            chkSubFolders.Enabled = True
            btnStart.Enabled = True
            btnStop.Enabled = False
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
        txtFileEvents.Text &= "File changed: " & e.FullPath & " change type: " & e.ChangeType & "  from " & Environment.UserDomainName & vbCrLf
    End Sub

    Public Sub OnCreated(ByVal source As Object, ByVal e As FileSystemEventArgs)
        Call GetIPDomain(ip1)
        Try

            If chkSilentMode.Checked Then
                WriteSilentLog("File Created: " & e.FullPath & " " & Now().ToString)
            Else

                If Me.InvokeRequired Then 'are we running on a secondary thread 
                    Dim d As New updatetextbox(AddressOf updateTextboxHandler)
                    Me.Invoke(d, New Object() {"File Created: " & e.FullPath & " " & Now().ToString & vbCrLf})
                Else
                    updateTextboxHandler("File Created: " & e.FullPath & " " & Now().ToString & " from " & vbCrLf)
                End If
                txtFileEvents.Text &= "File Created: " & e.FullPath & " " & Now().ToString & " from " & System.Net.IPAddress.HostToNetworkOrder(1) & vbCrLf
            End If
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Public Sub Ondeleted(ByVal source As Object, ByVal e As FileSystemEventArgs)

        Try
            If chkSilentMode.Checked Then
                WriteSilentLog("File Deleted: " & e.FullPath & " " & Now().ToString)
            Else
                'this is the correct way to deal with cross threading, and i was to much of a hurry to do the entire app this way so i ignore the errors now
                If Me.InvokeRequired Then 'are we running on a secondary thread 
                    Dim d As New updatetextbox(AddressOf updateTextboxHandler)
                    Me.Invoke(d, New Object() {"File Deleted: " & e.FullPath & " " & Now().ToString & vbCrLf})
                Else
                    updateTextboxHandler("File Deleted: " & e.FullPath & " " & Now().ToString & " from " & vbCrLf)
                End If
                txtFileEvents.Text &= "File Deleted: " & e.FullPath & " " & Now().ToString & " from " & vbCrLf
            End If
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Public Sub OnRenamed(ByVal source As Object, ByVal e As RenamedEventArgs)
        Try
            If chkSilentMode.Checked Then
                WriteSilentLog("File renamed from: " & e.OldName & " to: " & e.Name & " " & Now().ToString)
            Else
                'this is the correct way to deal with cross threading, and i was to much of a hurry to do the entire app this way so i ignore the errors now
                If Me.InvokeRequired Then 'are we running on a secondary thread 
                    Dim d As New updatetextbox(AddressOf updateTextboxHandler)
                    Me.Invoke(d, New Object() {"File renamed from: " & e.OldName & " to: " & e.Name & " " & Now().ToString & vbCrLf})
                Else
                    updateTextboxHandler("File renamed from: " & e.OldName & " to: " & e.Name & " " & Now().ToString & vbCrLf)
                End If
                txtFileEvents.Text &= "File renamed from: " & e.OldName & " to: " & e.Name & " " & Now().ToString & " from " & vbCrLf
            End If
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

        Me.Close()
        Me.Dispose()

    End Sub

    Private Sub WriteSilentLog(ByVal strTexttoWrite As String)
        Dim fs As New FileStream(System.Configuration.ConfigurationSettings.AppSettings.Get("LogFileName"), FileMode.OpenOrCreate, FileAccess.Write)

        Dim sw As New StreamWriter(fs)
        sw.BaseStream.Seek(0, SeekOrigin.End)
        sw.WriteLine(strTexttoWrite.ToString)
        sw.Close()

    End Sub


    Private Sub chkSilentMode_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSilentMode.CheckedChanged
        If chkSilentMode.Checked Then
            txtFileEvents.Enabled = False
        Else
            txtFileEvents.Enabled = True
        End If
    End Sub

    Private Sub updateTextboxHandler(ByVal TextboxText As String)
        ' txtFileEvents.Text = TextboxText
    End Sub

    ''' <summary>
    ''' This is the event that gets raised when the path becomes available after being unavailable
    ''' </summary>
    ''' <param name="Message"></param>
    ''' <remarks></remarks>
    Private Sub myfswFileWatcher_NetworkPathAvailable(ByVal Message As String) Handles myfswFileWatcher.NetworkPathAvailable
        Try
            'Ok the network path is available now
            StartFileSystemWatcher()
        Catch ex As Exception

        End Try
    End Sub

    ''' <summary>
    ''' This is the event that gets raised if the path becomes unavailable, be it a network problem or the folder gets deleted.
    ''' </summary>
    ''' <param name="Message"></param>
    ''' <remarks></remarks>
    Private Sub myfswFileWatcher_NetworkPathUnavailable(ByVal Message As String) Handles myfswFileWatcher.NetworkPathUnavailable
        Try
            'There was a network error we need to destroy the filesystemwatcher object and try to recreate it.
            'Send an email saying there is a netowrk error????
            'SendMail

            'now we have to stop and kill the current filesystemwatcher. we will recreate it in the available event.
            StopFileSystemWatcher()
            myfswFileWatcher.Dispose()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub




the above code get all information about file(created,changed,deleted,renamed).
In server ,there are many user access the file using our username and password. And I have to also run this program in server, server have status of all user who are connected to server using username and password.

Thanks
Regards
Vijay Kumar
India.
GeneralRe: Get IP Address and username using FileSystemWatcher in vb.net2.0 Pin
Dave Kreskowiak11-Aug-09 18:00
mveDave Kreskowiak11-Aug-09 18:00 
GeneralRe: Get IP Address and username using FileSystemWatcher in vb.net2.0 Pin
Luc Pattyn11-Aug-09 23:09
sitebuilderLuc Pattyn11-Aug-09 23:09 
GeneralRe: Get IP Address and username using FileSystemWatcher in vb.net2.0 Pin
Pandey Vijay Kumar S.12-Aug-09 0:51
Pandey Vijay Kumar S.12-Aug-09 0:51 
GeneralRe: Get IP Address and username using FileSystemWatcher in vb.net2.0 Pin
Dave Kreskowiak12-Aug-09 6:19
mveDave Kreskowiak12-Aug-09 6:19 
Questioni have one doubt in vb.net Pin
skumari11-Aug-09 2:20
skumari11-Aug-09 2:20 
AnswerRe: i have one doubt in vb.net Pin
dan!sh 11-Aug-09 2:59
professional dan!sh 11-Aug-09 2:59 
QuestionMediaplayer and duration Pin
JR21211-Aug-09 0:41
JR21211-Aug-09 0:41 
AnswerRe: Mediaplayer and duration Pin
Dave Kreskowiak11-Aug-09 4:07
mveDave Kreskowiak11-Aug-09 4:07 
QuestionIListSource Implementation Pin
Ovais Memon10-Aug-09 20:01
Ovais Memon10-Aug-09 20:01 
AnswerRe: IListSource Implementation Pin
Dave Kreskowiak11-Aug-09 3:50
mveDave Kreskowiak11-Aug-09 3:50 
GeneralRe: IListSource Implementation Pin
Ovais Memon11-Aug-09 5:01
Ovais Memon11-Aug-09 5:01 
GeneralRe: IListSource Implementation Pin
Henry Minute11-Aug-09 5:11
Henry Minute11-Aug-09 5:11 
GeneralRe: IListSource Implementation Pin
Dave Kreskowiak11-Aug-09 5:14
mveDave Kreskowiak11-Aug-09 5:14 
GeneralRe: IListSource Implementation Pin
Ovais Memon11-Aug-09 5:25
Ovais Memon11-Aug-09 5:25 
GeneralRe: IListSource Implementation Pin
Dave Kreskowiak11-Aug-09 6:48
mveDave Kreskowiak11-Aug-09 6:48 
AnswerRe: IListSource Implementation Pin
Mycroft Holmes11-Aug-09 16:21
professionalMycroft Holmes11-Aug-09 16:21 
QuestionMove,Resize and Drag and Drop a control Pin
Anubhava Dimri10-Aug-09 18:17
Anubhava Dimri10-Aug-09 18:17 

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.