Click here to Skip to main content
Licence 
First Posted 14 Aug 2004
Views 87,672
Downloads 925
Bookmarked 45 times

Retrieve detailed information of a File

By cuepack | 14 Aug 2004
The article shows how to get the detailed information of a file like comments, author...

1
1 vote, 6.7%
2
1 vote, 6.7%
3
6 votes, 40.0%
4
7 votes, 46.7%
5
4.38/5 - 15 votes
1 removed
μ 4.24, σa 1.55 [?]

Sample Image - DetailFileInfo.jpg

Introduction

This article shows, how one omitted the detail information of a file under the use of the Shell32.dll from the Windows system. Some detailed information are: Comment, Title, Subject, Category, Author, and so on.

Background

The Windows system could store additional information like author, comment, title, category... to a file, this information can be read with GetDetailsOf method from the shell32.dll.

Using the code

First of all, add a new COM reference "Microsoft Shell Controls and Automation" (shell32.dll) to your Project.

After adding the reference, simple create an instance of the CFileInfo class as in the demo project. To access the File Information, simply read the properties from the class.

try{
  // Read File Details from CFileInfo Object
  CFileInfo oDetailedFileInfo = new CFileInfo(sFileName);
  txtName.Text = oDetailedFileInfo.FileName;
  txtFiletype.Text = oDetailedFileInfo.FileType;
  txtFileSize.Text = oDetailedFileInfo.FileSize.ToString();
  txtAuthor.Text = oDetailedFileInfo.FileAuthor;
  txtCategory.Text = oDetailedFileInfo.FileCategory;
  txtComment.Text = oDetailedFileInfo.FileComment;
  txtSubject.Text = oDetailedFileInfo.FileSubject;
  txtTitle.Text = oDetailedFileInfo.FileTitle;
}catch(Exception ex){
  MessageBox.Show("Could not read File information\r\n" 
                  + ex.Message, "Error while getting Info", 
                  MessageBoxButtons.OK,MessageBoxIcon.Error);
}

Behind the Scenes

The GetDetailedFileInfo method gets all available information of a file into an ArrayList. The DetailedFileInfo class is a helper class for holding the information in a simple object within the ArrayList.

// Getting all the available Information of a File into a Arraylist
private ArrayList GetDetailedFileInfo(string sFile){
  ArrayList aReturn = new ArrayList();
  if(sFile.Length>0){
    try{
      // Creating a ShellClass Object from the Shell32
      ShellClass sh = new ShellClass();
      // Creating a Folder Object from Folder that inculdes the File
      Folder dir = sh.NameSpace( Path.GetDirectoryName( sFile ) );
      // Creating a new FolderItem from Folder that includes the File
      FolderItem item = dir.ParseName( Path.GetFileName( sFile ) );
      // loop throw the Folder Items
      for( int i = 0; i < 30; i++ ) {
        // read the current detail Info from the FolderItem Object
        //(Retrieves details about an item in a folder. 
        //For example, its size, type, or the time 
        //of its last modification.)

        // some examples:
        // 0 Retrieves the name of the item. 
        // 1 Retrieves the size of the item.
        // 2 Retrieves the type of the item.
        // 3 Retrieves the date and time that the item was last modified.
        // 4 Retrieves the attributes of the item.
        // -1 Retrieves the info tip information for the item. 

        string det = dir.GetDetailsOf( item, i );
        // Create a helper Object for holding the current Information
        // an put it into a ArrayList
        DetailedFileInfo oFileInfo = new DetailedFileInfo(i,det);
        aReturn.Add(oFileInfo);
      }

    }catch(Exception){

    }
  }
  return aReturn;
}
...

// Helper Class from holding the detailed File Informations
// of the System
public class DetailedFileInfo{
  int iID = 0;
  string sValue ="";

  public int ID{
    get{return iID;}
    set{iID=value;}
  }
  public string Value{
    get{return sValue;}
    set{sValue = value;}
  }

  public DetailedFileInfo(int ID, string Value){
    iID = ID;
    sValue = Value;
  }
}

History

  • First release - 15th August 2004.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

cuepack

Software Developer (Senior)

Switzerland Switzerland

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDate Created in the Summary Section PinmemberAbdul Rahman El Habboub0:14 22 Feb '11  
GeneralNot Working in Vista 64 PinmemberTanmoy Mitra2:27 9 Dec '10  
QuestionCan any 1 tell me how can i found Keyword Information PinmemberSheetalJain1:10 14 Mar '10  
QuestionGet Summary PinmemberJackielu200422:04 27 Aug '08  
QuestionNo Keyword? PinmemberMember 9914488:56 29 May '08  
GeneralVISTA Support Pinmemberalmkristl12:40 27 Aug '07  
GeneralRe: VISTA Support PinsussJasonJ8:02 4 Dec '07  
GeneralMapped Drive Problem Pinmemberdwarf8817:52 8 Aug '07  
GeneralRevision Number PinmemberAwaKe2:36 15 Feb '06  
QuestionLastSavedBy name Pinmembera_kavitha03@yahoo.co.in0:13 21 Dec '05  
Generalshell32.dll Pinmembererobles2k@yahoo.com10:28 6 Oct '05  
QuestionRe: shell32.dll Pinmemberrreeder3:38 28 Feb '07  
GeneralReading info from CD PinmemberSemt-x10:36 7 Apr '05  
GeneralWriting This Information PinmemberFinallyInSeattle9:19 6 Apr '05  
GeneralWindows 2000 PinmemberRobertBoe0:54 28 Feb '05  
GeneralRe: Windows 2000 Pinmembercuepack22:21 22 Mar '05  
GeneralRe: Windows 2000 PinmemberRobertBoe6:25 23 Mar '05  
QuestionHow to WRITE this data? PinmemberJohn Hind9:09 22 Oct '04  
AnswerRe: How to WRITE this data? PinsussAnonymous5:45 4 Mar '05  
AnswerRe: How to WRITE this data? PinsussAnonymous23:08 1 Sep '05  
AnswerRe: How to WRITE this data? Pinmember~Dim~7:03 27 Mar '07  
GeneralEnhancement PinmemberAllanY1:35 19 Aug '04  
QuestionDemoSourceCode ? PinmemberAntonio Barros2:39 16 Aug '04  
AnswerRe: DemoSourceCode ? Pinmembercuepack4:47 16 Aug '04  
GeneralLooks good! PinmemberLabrat00214:49 15 Aug '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 15 Aug 2004
Article Copyright 2004 by cuepack
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid