File type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chris52672
    New Member
    • Mar 2009
    • 26

    #1

    File type

    In a ListView box I want to list the file type.

    Example if in the list box the Name is foo.txt the Type would be Text Document.

    I thought using the FileInfo class would help but I am a bit lost.

    I tried
    string[] CipherFiles = System.IO.Direc tory.GetFiles(@ "C:\Cipher\Ciph erResult");

    //File Info for file we looked at
    System.IO.FileI nfo fi = new System.IO.FileI nfo(CipherFiles[0]);

    object FileTypeObj = fi.GetType();

    Console.WriteLi ne("object o = fi: Type is {0}", fi.GetType());

    But am not sure how to get the type. I have to believe that the type is registered somewhere and I can tap into it but I do not have a clue at this point.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    It's type is... "file". Period. Doesn't matter if its a photoshop file or a text file. Its just a bunch o' bits.

    Nothing stops you from renaming .psd to .txt , right? But does that in any way actually change the type of file or it's content structure?

    Some company's write data into the header to identify the file and its type, or even version of the type. A .Doc that is from Word 95 or a .doc from Word 2008 are still shown as .doc yet the program reads them differently by reading the header, getting a version, and going from there.

    You see some graphic programs that are smart enough to open an image regardless of the extension because they don't presume the extension is right but instead read into the file and make a determination based on the header.

    I would recommend making a Dictionary with the extension as the key and your description as the value. They you can display whatever you like for any type.

    Comment

    • chris52672
      New Member
      • Mar 2009
      • 26

      #3
      Ok I like that sugestion, but what about the picture of the file that I see in list boxes? How do I get that. There seems to be a little picture infront of the name of a file or folder. That is also something I would like to do.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I've never had a need to put a picture in a listview

        What does the MSDN Library have to say about it?

        Comment

        Working...