Get
If Not (ViewState("m_currentFolderPath") Is Nothing) Then
Return ViewState("m_currentFolderPath").ToString().Trim()
Else
Return String.Empty
End If
End Get
Set(ByVal value As String)
ViewState("m_currentFolderPath") = value
End Set
End Property
Protected Sub buttonDisplay_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim folderPath As String = txtBoxInput.Text
Dim theFolder As New DirectoryInfo(folderPath)
If theFolder.Exists Then
DisplayFolderList(theFolder.FullName)
Return
End If
Dim theFile As New FileInfo(folderPath)
If theFile.Exists Then
DisplayFolderList(theFile.Directory.FullName)
Return
End If
Throw New FileNotFoundException("There is no file or folder with " + "this name: " + txtBoxInput.Text)
Catch ex As Exception
Response.Write(("<script language='javascript'>window.alert('" + ex.Message + "');</script>"))
Me.ClearAllFields()
End Try
End Sub
Protected Sub DisplayFileInfo(ByVal fileFullName As String)
Dim theFile As New FileInfo(fileFullName)
If Not theFile.Exists Then
Throw New FileNotFoundException("File not found: " + fileFullName)
End If
txtBoxFileName.Text = theFile.Name
txtBoxCreationTime.Text = theFile.CreationTime.ToLongTimeString()
txtBoxLastAccessTime.Text = theFile.LastAccessTime.ToLongDateString()
txtBoxLastWriteTime.Text = theFile.LastWriteTime.ToLongDateString()
txtBoxFileSize.Text = theFile.Length.ToString() + " bytes"
End Sub
Protected Sub DisplayFolderList(ByVal folderFullName As String)
Dim theFolder As New DirectoryInfo(folderFullName)
If Not theFolder.Exists Then
Throw New DirectoryNotFoundException("Folder not found: " + folderFullName)
End If
ClearAllFields()
txtBoxFolder.Text = theFolder.FullName
currentFolderPath = theFolder.FullName
Dim nextFolder As DirectoryInfo
For Each nextFolder In theFolder.GetDirectories()
listBoxFolders.Items.Add(nextFolder.Name)
Next nextFolder
Dim nextFile As FileInfo
For Each nextFile In theFolder.GetFiles()
listBoxFiles.Items.Add(nextFile.Name)
Next nextFile
End Sub
Protected Sub ClearAllFields()
listBoxFolders.Items.Clear()
listBoxFiles.Items.Clear()
txtBoxFolder.Text = ""
txtBoxFileName.Text = ""
txtBoxCreationTime.Text = ""
txtBoxLastAccessTime.Text = ""
txtBoxLastWriteTime.Text = ""
txtBoxFileSize.Text = ""
End Sub
Protected Sub listBoxFolders_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim selectedString As String = listBoxFolders.SelectedItem.ToString()
Dim fullPathName As String = Path.Combine(currentFolderPath, selectedString)
DisplayFolderList(fullPathName)
Catch ex As Exception
Response.Write(("<script language='javascript'>window.alert('" + ex.Message + "');</script>"))
End Try
End Sub
Protected Sub listBoxFiles_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim selectedString As String = listBoxFiles.SelectedItem.ToString()
Dim fullFileName As String = Path.Combine(currentFolderPath, selectedString)
DisplayFileInfo(fullFileName)
Catch ex As Exception
Response.Write(("<script language='javascript'>window.alert('" + ex.Message + "');</script>"))
End Try
End Sub
Protected Sub buttonUp_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim folderPath As String = New FileInfo(currentFolderPath).DirectoryName
If Not (folderPath Is Nothing) Then
DisplayFolderList(folderPath)
Else
ClearAllFields()
Response.Write("<script language='javascript'>window.alert('Folder not found ');</script>")
End If
Catch ex As Exception
Response.Write(("<script language='javascript'>window.alert('" + ex.Message + "');</script>"))
End Try
End Sub
End Class