Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use XML (parser) to create Custom Outlook Views ?

COM and Automation

How to use XML (parser) to create Custom Outlook Views ?

by  Docpro777  Posted    (Edited  )
1) First, generate an appropriate custom table view manually in Outlook, Now 'Modify' it within Outlook's View Menu.

2) Create an XML file generator.prg as follows: copy the following code with Outlook OPEN, i.e.,:

#Define olFolderCalendar 9
objView = CreateView("New Calendar Table View",olFolderCalendar,0)
***
Function CreateView
Parameters strName,cnstFolderName,cnstViewType
PUBLIC objViews as Views
PUBLIC objViewCalendar as View
oOutlook = Createobject("Outlook.Application")
objXML=Createobject("MSXML2.DomDocument")

objViews = oOutlook.getnamespace("MAPI").GetDefaultFolder(cnstFolderName).Views

For Each objView In objViews
If objView.Name=strName
?objView.name
=STRTOFILE(objView.XML,'MyXMLfile') &&the XML suffix generates the XML code file
Endif
Endfor

3. Voila: You've just created your custom Outlook table that EVEN INCLUDES YOUR USER DEFINED FIELDS complete with properties, format(s), etc. in XML.
Note: USER DEFINED FIELDS are practically impossible to write in XML directly. E.g.: This is what MS Outlook generated in XML for "MyUserDefinedField" (a User Defined Field):
<column>
<heading>MyUserDefinedField</heading>
<prop>http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/MyUserDefinedField</prop>
<type>boolean</type>
<width>36</width>
<style>text-align:center;padding-left:3px</style>
<format>boolicon</format>
<displayformat>3</displayformat>
</column>

4. Next, Open the (temporary) MyXMLfile itself and copy (to the clipboard) all the XML code that was generated by outlook ...via VFP's STRTOFILE(objView.XML,'MyXMLfile') statement. Open notepad and label your XML file as you'd wish: In this example you might label that file "objViewCalendar.XML"

5. Finally, label another program and copy this code into it:
#DEFINE olTableView 0
=SetTableProperties("New Calendar Table View") &&This parameter name is arbitrary
****
FUNCTION SetTableProperties
PARAMETERS strViewName
PUBLIC objViews as Views
PUBLIC objViewCalendar as View
oOutlook = Createobject("Outlook.Application")
objXML=Createobject("MSXML2.DomDocument")

objViews = oOutlook.GetNamespace("MAPI").GetDefaultFolder(9).Views &&InBox
objViewCalendar = objViews.ADD(strViewName,olTableView,0)

objXML.load("objViewCalendar.XML")
objViewCalendar.XML = objXML.XML &&MUST KEEP THIS

objViewCalendar.Save
objViewCalendar.Apply

It is finished. Now just tie up any loose ends and integrate it into your COM object(s) and application. Refine your XML file directly, save it, and/or repeat/modify some of the steps above.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top