|
-
Jan 16th, 2005, 02:28 PM
#1
Thread Starter
Member
cant get my file browser to show correct file type - check out the screenshot
can someone help me get the file types to show up correctly? It should say the type such as text document, excel spreadsheet...etc. can someone tell me how i should change the fl.GetType.ToString to get it to show up right?
Here is what it looks like now
VB Code:
Dim fldr As DirectoryInfo
Dim fl As FileInfo
Dim count As Integer
Dim tempFile
Dim pos As Integer
Try
Directory.SetCurrentDirectory(txtPath.Text())
Catch e As Exception
MsgBox(e.Message(), MsgBoxStyle.Critical, "")
Exit Sub
End Try
listView1.Items.Clear()
Dim currFldr As New DirectoryInfo(Directory.GetCurrentDirectory)
If currFldr.FullName() <> currFldr.Root.ToString Then
listView1.Items.Add("..", 1)
count += 1
End If
For Each fldr In currFldr.GetDirectories()
If File.Exists(fldr.Name + "\folder.jpg") Then
With listView1
.Items.Add(fldr.Name, 3)
.Items(count).SubItems.Add("")
.Items(count).SubItems.Add(fldr.GetType.Name())
.Items(count).SubItems.Add(fldr.LastWriteTime)
End With
Else
With listView1
.Items.Add(fldr.Name, 2)
.Items(count).SubItems.Add("")
.Items(count).SubItems.Add(fldr.GetType.Name())
.Items(count).SubItems.Add(fldr.LastWriteTime)
End With
End If
count += 1
Next
For Each fl In currFldr.GetFiles()
tempFile = fl.Name()
pos = tempFile.LastIndexOf(".")
If pos > 0 Then
tempFile = tempFile.Substring(0, pos)
End If
If File.Exists(tempFile + ".tbn") Then
With listView1
.Items.Add(fl.Name, 5)
.Items(count).SubItems.Add(Format(Math.Ceiling(fl.Length / 1024), "###,###,###,###,###") & " KB")
.Items(count).SubItems.Add(fl.GetType.ToString)
.Items(count).SubItems.Add(fl.LastWriteTime)
End With
Else
With listView1
.Items.Add(fl.Name, 4)
.Items(count).SubItems.Add(Format(Math.Ceiling(fl.Length / 1024), "###,###,###,###,###") & " KB")
.Items(count).SubItems.Add(fl.GetType.ToString)
.Items(count).SubItems.Add(fl.LastWriteTime)
End With
End If
count += 1
Next
Last edited by charvelzeppelin; Jan 16th, 2005 at 02:51 PM.
-
Jan 16th, 2005, 03:12 PM
#2
Addicted Member
Re: cant get my file browser to show correct file type - check out the screenshot
Check this code out, notice that I extract the file type from the registry, not the type of the objects in the program themselves :
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myFileInfo As IO.FileInfo
Dim myDirInfo As IO.DirectoryInfo
Dim myLVItem As ListViewItem
For Each sDirPath As String In IO.Directory.GetDirectories("c:\")
myDirInfo = New IO.DirectoryInfo(sDirPath)
myLVItem = New ListViewItem(myDirInfo.Name)
myLVItem.SubItems.Add("")
myLVItem.SubItems.Add("Folder")
myLVItem.SubItems.Add(myDirInfo.LastWriteTime)
ListView1.Items.Add(myLVItem)
Next
For Each sFilePath As String In IO.Directory.GetFiles("c:\")
myFileInfo = New IO.FileInfo(sFilePath)
myLVItem = New ListViewItem(myFileInfo.Name)
myLVItem.SubItems.Add(Format(Math.Ceiling(myFileInfo.Length / 1024), "###,###,###,###,###") & " KB")
myLVItem.SubItems.Add(GetFileTypeFromRegistry(myFileInfo.Extension))
myLVItem.SubItems.Add(myFileInfo.LastWriteTime)
ListView1.Items.Add(myLVItem)
Next
End Sub
Private Function GetFileTypeFromRegistry(ByVal sFileExtension As String) As String
Dim myRegClsRoot As RegistryKey = Registry.ClassesRoot
Dim myRegKeyExt As RegistryKey
Dim myRegKeyFileType As RegistryKey
Dim sFileType As String
If Not sFileExtension.StartsWith(".") Then
sFileExtension = "." + sFileExtension
End If
myRegKeyExt = myRegClsRoot.OpenSubKey(sFileExtension, False)
If myRegKeyExt Is Nothing Then
Return "Unkown Extension"
End If
If myRegKeyExt.GetValue("") = "" Then
myRegKeyFileType.Close()
Return "Unknown Extension"
End If
myRegKeyFileType = myRegClsRoot.OpenSubKey(myRegKeyExt.GetValue(""), False)
sFileType = myRegKeyFileType.GetValue("")
myRegKeyFileType.Close()
myRegKeyExt.Close()
Return sFileType
End Function
There are no stupid questions, but a whole bunch of dumb sayings !
Save time on database code, try DataLG !
-
Jan 16th, 2005, 11:15 PM
#3
Thread Starter
Member
Re: cant get my file browser to show correct file type (resolved)
thanks, you're the man ....the function works great.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|