|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis 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. BackgroundThe Windows system could store additional information like author, comment, title, category... to a file, this information can be read with Using the codeFirst 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 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 ScenesThe // 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
|
||||||||||||||||||||||