Reading the custom properties of the word document without opening the word

S

sajin

Hi all,

I have arroud 50 word templates (.dot file) , i have a console
application which creates xml of custom properties of the word , but it
takes tooo much time to create ( meaning presently i a doing open each
template read the values and close ) is there is anotherway of doing
(meanung without opening or something ) . i want to speed up the
process

Here is the code

Imports Word
Imports Office
Imports System.Xml
Imports System.Data
Imports System.IO
Imports System.IO.Directory
Imports System.Diagnostics
Module Module1

Sub Main()
Dim or_RootPath As String
Const or_Root As String = "Mago"
Const or_Options As String = "Options"
Const or_Application_Path As String = "ApplicationPath"
Dim oWord As Word.Application
Dim oDoc As New Word.Document
Dim oBuiltInProps As Object
Dim filename As String
or_RootPath = GetSetting(or_Root, or_Options,
or_Application_Path)
filename = or_RootPath + "\TemplateFinder\TemplateFinder.xml"
Dim tw As New XmlTextWriter(filename,
System.Text.Encoding.Default)
tw.Formatting = Formatting.Indented
tw.WriteStartDocument()
tw.WriteStartElement("Templates")
'Template fields declaration
Dim templateName As String
Dim tags As String
Dim lastUsed As String
Dim useCount As String
Dim myRating As String
Dim category As String
Dim description As String
Dim modifiedDate As String
'End here
Dim strTemplatePath() As String
Dim StrTemplate As String
If Directory.Exists(or_RootPath + "\Templates") Then
strTemplatePath = Directory.GetFiles(or_RootPath +
"\Templates")
Dim oFalse As Object = False
Dim oMissing = System.Reflection.Missing.Value
For Each StrTemplate In strTemplatePath
If StrTemplate.Contains(".dot") Then
oWord = CreateObject("Word.Application")
oWord.Visible = False
Dim str As String =
StrTemplate.Substring(StrTemplate.LastIndexOf("\") + 1)
templateName = str.Substring(0,
str.LastIndexOf("."))
' Console.WriteLine(StrTemplate)
oDoc = oWord.Documents.Add(StrTemplate)
oBuiltInProps = oDoc.BuiltInDocumentProperties()
tags = oBuiltInProps.Item("Keywords").Value
lastUsed = ""
useCount = ""
myRating = "0"
category = oBuiltInProps.Item("Category").Value
description = oBuiltInProps.Item("Comments").Value
modifiedDate = ""
tw.WriteStartElement("Template")
Console.WriteLine(templateName)
tw.WriteAttributeString("Name", templateName)
tw.WriteElementString("Keywords", tags)
tw.WriteElementString("LastUsed", lastUsed)
tw.WriteElementString("UseCount", useCount)
tw.WriteElementString("MyRating", myRating)
tw.WriteElementString("Category", category)
tw.WriteElementString("Description", description)
tw.WriteElementString("ModifiedDate", modifiedDate)
tw.WriteEndElement()
oWord.Quit(oFalse, oMissing, oMissing)
End if
Next
tw.WriteEndElement()
tw.WriteEndDocument()
tw.Flush()
tw.Close()
End If
End Sub

End Module

Thanks in advance
Sajin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top