Results 1 to 7 of 7

Thread: [RESOLVED] File Type Info

  1. #1

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Resolved [RESOLVED] File Type Info

    I'm having trouble getting a files description...

    ie

    ".txt" = "Text Document"

    I do not want to use a registry lookup, as i doubt this is the way other programs do it ... i don't find it to be very efficient...

    Does anyone know any other ways of doing this?

    e.g.

    Code:
    lvitem.SubItems.Add(System.IO.File.GetAttributes((MyFiles(i))).GetType)
    ^
    |
    Doesn't work
    -BoKu-

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: File Type Info

    GetType is a method used to get the actual .NET framework type of a given object.

    File extension descriptions are in fact stored in the registry, and that is how you should go about retrieving them.

    How is it not very efficient to use the registry for this?

  3. #3

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: File Type Info

    Well I had a quick browse through the CLASSES_ROOT node and tried to find, BMP for bitmap

    found

    ".bmp"

    description

    "Paint.Picture"

    Although when I right click > properties > Type Of File

    it says

    "Bitmap Image"

    2 totally different descriptions ... so I'm just wondering where does the file properties window get its info from? and can I use it?
    -BoKu-

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: File Type Info

    what about this?
    Code:
            Dim myExtensionToFind As String = ".bmp"
            Dim myExtensionType As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & myExtensionToFind, String.Empty, String.Empty).ToString
            Dim myExtensionDescription As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & myExtensionType, String.Empty, String.Empty).ToString
    
            MessageBox.Show(String.Format("File Type {0} is : {1}", myExtensionToFind, myExtensionDescription))

  5. #5

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: File Type Info

    the myExtensionDescription always draws a blank :S for some reason mate?
    -BoKu-

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: File Type Info

    Quote Originally Posted by boku
    the myExtensionDescription always draws a blank :S for some reason mate?
    Can you give an extension example that Klienma's code would return a blank description?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  7. #7

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: File Type Info

    Nevermind, just had to move stuff around bit.

    Excellent work as usual Klienma

    I eat my words
    -BoKu-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width