Answered Getting file type

  • Wednesday, May 25, 2005 4:56 PM
     
     
    Hi!

       I want to retrieve de filetype of a file as a string in my app. This is what i use:

    Dim infofile As System.IO.FileInfo
    infofile = FileIO.FileSystem.GetFileInfo(
    "c:\tmp.txt")

    this way i can only get the extension .txt

    How to retrieve full extension description like "text document" or "Winzip archive" instead of ".zip" and so on...

    thank

All Replies

  • Thursday, May 26, 2005 4:54 PM
    Moderator
     
     Answered
    You can do this by using My.Computer.Registry to look this up in the Registry.

    Dim infofile As System.IO.FileInfo
    infofile = FileIO.FileSystem.GetFileInfo("c:\testzinio.txt")
    Dim fileExt As String = infofile.Extension

    Dim fileType As String
    fileType = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & fileExt, "", "")

    Dim fileDesc As String
    fileDesc = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & fileType, "", "")


    Robert

  • Friday, May 27, 2005 6:08 AM
     
     

    Thank for the help Robert.

  • Friday, June 10, 2005 9:41 AM
     
     
     Robert Green wrote:
    You can do this by using My.Computer.Registry to look this up in the Registry.

    Dim infofile As System.IO.FileInfo
    infofile = FileIO.FileSystem.GetFileInfo("c:\testzinio.txt")
    Dim fileExt As String = infofile.Extension

    Dim fileType As String
    fileType = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & fileExt, "", "")

    Dim fileDesc As String
    fileDesc = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & fileType, "", "")


    Robert


    Could you inform us of what Namespace the My.Computer.Registry is in? I'm trying to do the same thing but using C# not VB.NET
    [Retract]-- I just discovered this is only available in the 2005 version using 2.0 Framework. No help to me, but thanks for the information anyways!
    Thanks
    -RazrV3
  • Saturday, June 11, 2005 1:14 AM
    Moderator
     
     
    You can still access the Registry in .NET Framework 1.0/1.1, by importing the Microsoft.Win32 namespace.

  • Saturday, June 11, 2005 1:50 AM
    Moderator
     
     
    You can use the following code in v1.1



    string strFileExt = ".txt";
    RegistryKey objHKU = Registry.ClassesRoot;
    objHKU = objHKU.OpenSubKey(strFileExt);
    object objKey = objHKU(""); //Gets the value in (default)
    string strValue = objKey + "";

     


    Regards,
    Vikram