DSOFile and Summary PropertiesYesterday I posted about using ShellExecuteEx to display the document properties dialog for a file or folder. Displaying the properties dialog is nice, however I also need to access the OLE document properties (Document Summary Properties), the information that is stored on the Summary and Custom tabs of the properties dialog. I did quite a bit of searching, reading and testing in an attempt to find a simple solution. I did get to learn a lot about the Document Summary Properties and it looked like my only option was to head down the road using the IPropertyStorage Interface. As I was testing some code I came across the best little ActiveX component that can quickly access the property information. The Dsofile.dll is an ActiveX component is available from Microsoft. They even include a sample application (although the samples are in VB6 and VB7 they are useable). This component simplifies (I like things simple) setting and getting the document summary properties. The KB article and download mention that this is meant for Office files, however I have found that it works fine on other files as well (the exception being that the Office documents seem to be the only types of files with Custom Properties). The other great thing about this component is that "You have a royalty-free right to use, to modify, to reproduce, and to distribute the Dsofile.dll sample file component and the C++ source code files in any way you find useful." That quote is taken directly from the DSOfile.dll Article ID: 224351 that is listed on Microsoft's Support site. My thoughts, why reinvent the wheel when you really don't need to. I highly recommend using this component if you need to access the extended properties. As usual, I whipped up a sample application testing this components functionality. The meager sample code is listed here (image of application screen is also included in this post):
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
private void btnSelectFile_Click(object sender, EventArgs e)
...{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
...{
textBox1.Text = openFileDialog1.FileName;
toolTip1.SetToolTip(textBox1, textBox1.Text);
lstSummary.Items.Clear();
OleDocumentPropertiesClass odpc = new OleDocumentPropertiesClass();
odpc.Open(
@openFileDialog1.FileName,
false,
dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess
);
// Summary "Standard" Properties
ListViewItem lvTitle = new ListViewItem();
lvTitle.Group = lstSummary.Groups[0];
lvTitle.Text = "Title";
lvTitle.SubItems.Add(odpc.SummaryProperties.Title);
lstSummary.Items.Add(lvTitle);
ListViewItem lvSubject = new ListViewItem();
lvSubject.Group = lstSummary.Groups[0];
lvSubject.Text = "Subject";
lvSubject.SubItems.Add(odpc.SummaryProperties.Subject);
lstSummary.Items.Add(lvSubject);
ListViewItem lvCategory = new ListViewItem();
lvCategory.Group = lstSummary.Groups[0];
lvCategory.Text = "Category";
lvCategory.SubItems.Add(odpc.SummaryProperties.Category);
lstSummary.Items.Add(lvCategory);
ListViewItem lvKeyword = new ListViewItem();
lvKeyword.Group = lstSummary.Groups[0];
lvKeyword.Text = "Keywords";
lvKeyword.SubItems.Add(odpc.SummaryProperties.Keywords);
lstSummary.Items.Add(lvKeyword);
ListViewItem lvComments = new ListViewItem();
lvComments.Group = lstSummary.Groups[0];
lvComments.Text = "Comments";
lvComments.SubItems.Add(odpc.SummaryProperties.Comments);
lstSummary.Items.Add(lvComments);
ListViewItem lvAuthor = new ListViewItem();
lvAuthor.Group = lstSummary.Groups[1];
lvAuthor.Text = "Author";
lvAuthor.SubItems.Add(odpc.SummaryProperties.Author);
lstSummary.Items.Add(lvAuthor);
ListViewItem lvRevision = new ListViewItem();
lvRevision.Group = lstSummary.Groups[1];
lvRevision.Text = "Revision Number";
lvRevision.SubItems.Add(odpc.SummaryProperties.RevisionNumber);
lstSummary.Items.Add(lvRevision);
// Custom Properties
foreach (DSOFile.CustomProperty cp in odpc.CustomProperties)
...{
ListViewItem lvc = new ListViewItem();
lvc.Group = lstSummary.Groups[2];
lvc.Text=cp.Name;
lvc.SubItems.Add(cp.get_Value().ToString());
lstSummary.Items.Add(lvc);
}
odpc.Close(false);
}
}
}This is something I'd also like to port to Delphi for use in those applications. Maybe this week sometime......