BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 


Sunday, September 23, 2007
DSOFile and Summary Properties

Yesterday 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):

1 public partial class Form1 : Form
2 {
3 public Form1()
4 {
5 InitializeComponent();
6 }

7
8 private void btnSelectFile_Click(object sender, EventArgs e)
9 {
10 if (openFileDialog1.ShowDialog() == DialogResult.OK)
11 {
12 textBox1.Text = openFileDialog1.FileName;
13 toolTip1.SetToolTip(textBox1, textBox1.Text);
14 lstSummary.Items.Clear();
15
16 OleDocumentPropertiesClass odpc = new OleDocumentPropertiesClass();
17 odpc.Open(
18 @openFileDialog1.FileName,
19 false,
20 dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess
21 );
22 // Summary "Standard" Properties
23 ListViewItem lvTitle = new ListViewItem();
24 lvTitle.Group = lstSummary.Groups[0];
25 lvTitle.Text = "Title";
26 lvTitle.SubItems.Add(odpc.SummaryProperties.Title);
27 lstSummary.Items.Add(lvTitle);
28
29 ListViewItem lvSubject = new ListViewItem();
30 lvSubject.Group = lstSummary.Groups[0];
31 lvSubject.Text = "Subject";
32 lvSubject.SubItems.Add(odpc.SummaryProperties.Subject);
33 lstSummary.Items.Add(lvSubject);
34
35 ListViewItem lvCategory = new ListViewItem();
36 lvCategory.Group = lstSummary.Groups[0];
37 lvCategory.Text = "Category";
38 lvCategory.SubItems.Add(odpc.SummaryProperties.Category);
39 lstSummary.Items.Add(lvCategory);
40
41 ListViewItem lvKeyword = new ListViewItem();
42 lvKeyword.Group = lstSummary.Groups[0];
43 lvKeyword.Text = "Keywords";
44 lvKeyword.SubItems.Add(odpc.SummaryProperties.Keywords);
45 lstSummary.Items.Add(lvKeyword);
46
47 ListViewItem lvComments = new ListViewItem();
48 lvComments.Group = lstSummary.Groups[0];
49 lvComments.Text = "Comments";
50 lvComments.SubItems.Add(odpc.SummaryProperties.Comments);
51 lstSummary.Items.Add(lvComments);
52
53 ListViewItem lvAuthor = new ListViewItem();
54 lvAuthor.Group = lstSummary.Groups[1];
55 lvAuthor.Text = "Author";
56 lvAuthor.SubItems.Add(odpc.SummaryProperties.Author);
57 lstSummary.Items.Add(lvAuthor);
58
59 ListViewItem lvRevision = new ListViewItem();
60 lvRevision.Group = lstSummary.Groups[1];
61 lvRevision.Text = "Revision Number";
62 lvRevision.SubItems.Add(odpc.SummaryProperties.RevisionNumber);
63 lstSummary.Items.Add(lvRevision);
64
65 // Custom Properties
66 foreach (DSOFile.CustomProperty cp in odpc.CustomProperties)
67 {
68 ListViewItem lvc = new ListViewItem();
69 lvc.Group = lstSummary.Groups[2];
70 lvc.Text=cp.Name;
71 lvc.SubItems.Add(cp.get_Value().ToString());
72 lstSummary.Items.Add(lvc);
73 }

74 odpc.Close(false);
75 }

76 }

77 }

This is something I'd also like to port to Delphi for use in those applications. Maybe this week sometime......

Labels: , ,

posted by Brad Prendergast at 6:52:00 PM
Comments:
Links to this post:

Create a Link

Recent Posts
 ShellExecuteEX and ShellExecuteInfo Revisited
 A ToolStripMenuItem and a Check
 Who is copying your web site?
 A little FileIconInit for the System Image list
 Code Monkey
 A DataGridView, DataGridViewCheckBoxColumn, DataGr...
 Those Commercials
 System Information and the PerformanceCounter Clas...
 Cryptography hash and a class - to go
 C# LocalAdapterInformation


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger