Outlook 2003 – Problem with view modification

  • Thread starter Paulo Braz Figueiredo
  • Start date
P

Paulo Braz Figueiredo

Hi everyone,
I’m developing an Outlook 2003 Add-in. I need to alter a table view
(Microsoft.Office.Interop.Outlook.OlViewType.olTableView) applied over a
folder containing contacts. I’m trying to modify de XML property of the view
but the modifications don’t seem to be effective! Can anybody help me?
Anybody knows what’s happening? How can I do what I intent?
Here’s the code that I’m using to try this achive this goal:

Microsoft.Office.Interop.Outlook.MAPIFolder sent_folder;
Microsoft.Office.Interop.Outlook.MAPIFolder sent_sms_folder;
try {
sent_folder =
this.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail);
sent_sms_folder = sent_folder.Folders["Sent SMS"];
Outlook.Views sent_sms_views = sent_sms_folder.Views;
Outlook.View sent_sms_view = sent_sms_views.Add("Sent SMS View",
Microsoft.Office.Interop.Outlook.OlViewType.olTableView,
Microsoft.Office.Interop.Outlook.OlViewSaveOption.olViewSaveOptionThisFolderEveryone);
XmlNode node;
XmlDocument sent_sms_view_xml = new XmlDocument();
sent_sms_view_xml.LoadXml(sent_sms_view.XML);
node =
sent_sms_view_xml.DocumentElement.SelectSingleNode("//view/newitemrow");
node.InnerText = "0";
node =
sent_sms_view_xml.DocumentElement.SelectSingleNode("//view/incelledit");
node.InnerText = "0";
node =
sent_sms_view_xml.DocumentElement.SelectSingleNode("/view/column/heading[text()='Full Name']");
node.InnerText = "Message";
sent_sms_view.XML = "<?xml version=\"1.0\"?>" +
sent_sms_view_xml.DocumentElement.;
} catch {}

As you can see I’m trying to change de heading of a column of a table but
there’s no modification on the view! Anybody knows where’s my error?
 
P

Paulo Braz Figueiredo

Hi Ken Slovak,
I’m setting the view XML in the line:
sent_sms_view.XML = "<?xml version=\"1.0\"?>" +
sent_sms_view_xml.DocumentElement.OuterXml;

--
Paulo Figueiredo


Ken Slovak - said:
I don't see where you're setting the view XML?




Paulo Braz Figueiredo said:
Hi everyone,
I’m developing an Outlook 2003 Add-in. I need to alter a table view
(Microsoft.Office.Interop.Outlook.OlViewType.olTableView) applied over a
folder containing contacts. I’m trying to modify de XML property of the
view
but the modifications don’t seem to be effective! Can anybody help me?
Anybody knows what’s happening? How can I do what I intent?
Here’s the code that I’m using to try this achive this goal:

Microsoft.Office.Interop.Outlook.MAPIFolder sent_folder;
Microsoft.Office.Interop.Outlook.MAPIFolder sent_sms_folder;
try {
sent_folder =
this.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail);
sent_sms_folder = sent_folder.Folders["Sent SMS"];
Outlook.Views sent_sms_views = sent_sms_folder.Views;
Outlook.View sent_sms_view = sent_sms_views.Add("Sent SMS View",
Microsoft.Office.Interop.Outlook.OlViewType.olTableView,
Microsoft.Office.Interop.Outlook.OlViewSaveOption.olViewSaveOptionThisFolderEveryone);
XmlNode node;
XmlDocument sent_sms_view_xml = new XmlDocument();
sent_sms_view_xml.LoadXml(sent_sms_view.XML);
node =
sent_sms_view_xml.DocumentElement.SelectSingleNode("//view/newitemrow");
node.InnerText = "0";
node =
sent_sms_view_xml.DocumentElement.SelectSingleNode("//view/incelledit");
node.InnerText = "0";
node =
sent_sms_view_xml.DocumentElement.SelectSingleNode("/view/column/heading[text()='Full
Name']");
node.InnerText = "Message";
sent_sms_view.XML = "<?xml version=\"1.0\"?>" +
sent_sms_view_xml.DocumentElement.;
} catch {}

As you can see I’m trying to change de heading of a column of a table but
there’s no modification on the view! Anybody knows where’s my error?
 
K

Ken Slovak - [MVP - Outlook]

Sorry, I was unclear. Are you applying the new view XML? If you read back
the XML is it what you intended?
 
P

Paulo Braz Figueiredo

If I read back the XML property of the view with something like
MessageBox.Show(sent_sms_view.XML) the result isn’t what I intended!!!
 
K

Ken Slovak - [MVP - Outlook]

Try using View.Save followed by View.Apply and see if that makes a
difference.
 
P

Paulo Braz Figueiredo

Hi Ken Slovak,
I’m already doing that (Save() and Apply()) and the XML property remains
unchanged! :(
 
K

Ken Slovak - [MVP - Outlook]

Then I'm not sure what the problem is. As long as I create XML that isn't in
error I have no problems doing a view change. Are you sure the XML is
correct?

I'd most likely create a similar custom view in the UI, using the define
custom view dialog and then read that XML and attempt to apply it to a view.
That way you know the XML is valid and you can see if it's something in the
XML format or something structural.
 
P

Paulo Braz Figueiredo

I’m trying to change the name of a column of a view (Table type view), but…
When I read back after the modification the XML is unchanged!!! I’m using
contact items in the target folder of the view. Do you know what I’m doing
wrong? I really need to change the names of some columns!
 
K

Ken Slovak - [MVP - Outlook]

Did you do as I suggested and create the view you want in the UI as a new
view and then read the XML and use that in your code to verify if that will
work? I've had no problems here in changing the XML for a view although I
only do it using VBA or VB 6. The other thing to try is to do what you want
using Outlook VBA and see if that works. If so it's something in how you're
using the OOM from the Interop.
 
P

Paulo Braz Figueiredo

You have reason when I read from an xml file and affect the result to the XML
property of a view all works fine. I don’s understand why my XmlDocument
doesn’t work and de xml read from a file works.
Thanks for the help,

Paulo Figueiredo
 
K

Ken Slovak - [MVP - Outlook]

I have no idea, you can compare the XML from one and the other to see if
there are any differences. Obviously if one works and the other doesn't
there must be some differences.
 

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