Creating Task Views Methodically

  • Thread starter Thread starter tomthedev
  • Start date Start date
T

tomthedev

All, I have been trying to create views through code unsuccessfully through
several examples. I can run code and get at views xml where the view has
been created by the Outlook GUI. Is there a straightforward way the xml
generated can be used to create views on different Outlook
installations/desktops? If so, are there
any samples of adding a view with xml dynamically? I have seen a couple
with DOM and LoadXML method, but have not gotten the views to add in the
first place.
Thank you!
 
I've installed custom views on machines as part of my addin run, but I
haven't done any dynamic creation of the XML.

I've always used canned XML files or resources that I've created and
debugged first.

There's no reason why the view XML can't be created on the fly and then
assigned as the current view or one of the available views for a folder or
folder type, but you have to make sure any view XML created that way will
actually work.

If these are canned views that don't depend on something on the target
system to be custom then why go through all that work? Why not just use
canned XML that you know will work?

Most of the sample view XML stuff I've run into has been at
www.outlookcode.com.
 
Ken,
Thank you very much for your reply.

In concept, can I create the xml in the GUI, save it out or look at it, then
reproduce the xml in code and add it in outlook through the code?
I would think this could be the case. The only part I question is being
able to add the view in code in a stable manner. I saw an example for
views.add and load.xml, but could get neither to work. Perhaps if I get back
to basics have a sample that works(even it is very simple)?

Your help is greatly appreciated!
 
What I usually do is to set up a view in the UI as close to what I want as
possible. Then I grab that view XML and modify it by hand (or code) to add
whatever else I want there. In that way for example I can add a column for a
MAPI property I've added that isn't in UserProperties.

Once that's done I can persist the XML as a string resource or a file and
use it. Certainly you can use XML coding and the DOM to set up properly
formed view XML, the end result would be the same as long as the XML is well
formed for the view schema.

At runtime I'd add my view XML to the MAPIFolder.Views collection either on
the fly when handling a button click or an Explorer folder change event with
whatever save options I wanted. Then I'd set the CurrentView to that view
and save it and apply it. It seems to work OK for me.
 
Ken, that is really insightful. Thanks again!
When you add in the view, how can this be done? Must it be an Add-In
(whether COM or .Net)
or is an automation object in VBScript possible where Outlook is not opened?
Regards,
 
Any language that supports COM can be used. But to work with Outlook it has
to be opened, no matter what language you're using.
 
Here is a sub I am trying to use to modify a view's XML property. It doesn't
work but I get no errors. The only thing I can infer is the XML is being
rejected (withoiut an error raised), but the only editing I did was to the
name description fields to be displayed. The text editor I used change some
of the indent spacing in hte XML code, but I don't know if it changed EOF
etc. Is there an MS XML test program to validate View.XML coding?

Private Sub XMLView()

Dim fso, aFile
Dim newView As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.OpenTextFile("Q:\_Tools\Courts\CourtViewTest.txt")
newView = aFile.Readall
aFile.Close

Dim objViews As Outlook.Views
Dim objView As Outlook.View
Set objViews = Application.ActiveExplorer.CurrentFolder.Views
Set objView = objViews.Item("Court View Test")
If objView Is Nothing Then
Set objView = objViews.Add("Court View Test", olCardView,
olViewSaveOptionThisFolderEveryone)
End If

objView.XML = newView
objView.Save
objView.Apply
objViews("Court View Test").XML = newView
objViews("Court View Test").Save
objViews("Court View Test").Apply

MsgBox objViews("Court View Test").XML
MsgBox Application.ActiveExplorer.CurrentView.XML

End Sub
 
I should have added I opened the text file in MS Word but had no Outlook View
schema with which to validate it.
 
Back
Top