creating outlook inspector pages with C#

T

Tony Feldmesser

Hi All,
I am trying to programmatically create a custom page inside the contact
inspector of outlook 2003 using an add-in created with Visual C# 2003 and
Visual Studio Tools for Office 2003. I have a simple add-in that places a
button on a command bar, and clicking that button executes the code below. I
do see the new page "Test" in the inspector, but the last line before the
catch, "myPage = (Page) obj;", throws an invalid cast exception. So if the
new object is not a 'Page', then what is it? I get the same error if I try
to get the page with "myPage = (Page) myPages["Test"];". Any suggestions
would be welcome!

Regards,

Tony
~~~~~

try
{
ContactItem myContact;
Inspector myInspector;
Outlook.Pages myPages;
Page myPage;

myContact = (ContactItem) outlookApp.CreateItem(
Outlook.OlItemType.olContactItem);

myContact.FullName = "Test Contact";
myInspector = myContact.GetInspector;
myPages = (Outlook.Pages) myInspector.ModifiedFormPages;

object obj = myPages.Add("Test");

myInspector.ShowFormPage("Test");
myContact.Display(false);

myPage = (Page) obj; // <<< this fails

// do stuff with the page here ...
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
 
K

Ken Slovak - [MVP - Outlook]

I don't know why your code is falling over, I don't do C# addins, but it's
never a good idea to add a page on the fly to an Outlook item. That will
one-off the item, which usually has bad consequences.
 
T

Tony Feldmesser

Hi Ken,
Thanks for the reply, although I'm not sure I understand what you mean by
"one-off the item". I am, however, an absolute beginner to outlook
programming, so I guess I'm talking to the right man! My ultimate goal here
is to create a way for a user to input and store some custom information,
tied to a specific contact item, and then to be able to pass that information
on to my application later (through some other means, probably a COM
interface). Can you suggest a better way to approach this?

Regards,

Tony
~~~~~~

Ken Slovak - said:
I don't know why your code is falling over, I don't do C# addins, but it's
never a good idea to add a page on the fly to an Outlook item. That will
one-off the item, which usually has bad consequences.




Tony Feldmesser said:
Hi All,
I am trying to programmatically create a custom page inside the contact
inspector of outlook 2003 using an add-in created with Visual C# 2003 and
Visual Studio Tools for Office 2003. I have a simple add-in that places a
button on a command bar, and clicking that button executes the code below.
I
do see the new page "Test" in the inspector, but the last line before the
catch, "myPage = (Page) obj;", throws an invalid cast exception. So if
the
new object is not a 'Page', then what is it? I get the same error if I
try
to get the page with "myPage = (Page) myPages["Test"];". Any suggestions
would be welcome!

Regards,

Tony
~~~~~

try
{
ContactItem myContact;
Inspector myInspector;
Outlook.Pages myPages;
Page myPage;

myContact = (ContactItem) outlookApp.CreateItem(
Outlook.OlItemType.olContactItem);

myContact.FullName = "Test Contact";
myInspector = myContact.GetInspector;
myPages = (Outlook.Pages) myInspector.ModifiedFormPages;

object obj = myPages.Add("Test");

myInspector.ShowFormPage("Test");
myContact.Display(false);

myPage = (Page) obj; // <<< this fails

// do stuff with the page here ...
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
 
K

Ken Slovak - [MVP - Outlook]

See the section on one-off forms at http://www.outlookcode.com/d/formpub.htm
for some explanation of that.

What I'd probably do, depending on how I wanted to implement things would be
to add a button to the Inspector to open a non-Outlook form that would
gather the information I wanted. I'd then store it in UserProperties in the
item or directly in a database or whatever. If I needed a custom form I'd
design it and access it from code or by making it a default form. If needed
I'd publish the form using code in my COM addin so it would be available for
use in the UI and with code. By changing the MessageClass of an item in the
Inspector to the custom MessageClass of the custom form the user would see
the custom form with the custom page. I'd do that in the NewInspector event
handler.
 
T

Tony Feldmesser

Hi Ken,
Excellent--I'll try that approach! Thanks for the help!

Tony
~~~~~~~
 

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