retrieving values from custom outlook form using vsto and c#

N

nitro

Hi,

I'm a newbe to all of these technologies so please bear with me.

I have a .oft created, which is basically a meeting request form with a
couple radio buttons and a text box present in a new tab. I am able to
display the form using the code below but I can't seem to access the values
that the users enter into these additional fields. Essentially, what I'm
trying to do is to present this form to a user and obtain their inputs from
the form before they hit send. Can someone please tell me how to add to the
code below in order to retrieve (and even save within Outlook) the values of
these additional fields that I've defined.


<code>
Outlook._Application olApp = new Outlook.ApplicationClass();
Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
Outlook.MAPIFolder foldername =
olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook._AppointmentItem oAppointment =
(Outlook._AppointmentItem)olApp.CreateItemFromTemplate("C:/OutlookForms/TelePresenceForm2.oft", foldername);
oAppointment.Display(true);
</code>


Thanks.
 
K

Ken Slovak - [MVP - Outlook]

You need to get an Inspector object for that item, using
oAppointment.GetInspector(). The Inspector will have a ModifiedFormPages
collection. Use the name of your custom tab as the argument to get that
specific tab and then get the tab's Controls property. from there you get
your specific control and read its value. Note that such control values will
not be preserved unless the controls are bound to Outlook properties, either
standard or custom.

Take a look at the Forms information at www.outlookcode.com for lots of
information on how specifically to do all that. You can search there on
"ModifiedFormPages" to get that specific information.
 
N

nitro

Hi Ken,

Thanks for the reply. This approach would probably work if I was using VBA
or VB script from within the Outlook form but I'm using C#, VSTO and Visual
Studio 2008. So I believe I have to display the form and then handle some
sort of events that trigger when the user modify some controls on the forms.
Problem is I don't know what events these are and how to invoke them. Can you
maybe shed some light on this. I know this is more of a VSTO issue and I've
posted on the VSTO forum too but no one has responded so far.

Thanks.
 
K

Ken Slovak - [MVP - Outlook]

It's not a VSTO problem at all. The code would be the same or similar in C#
for a shared addin, VSTO or a standalone application. If you get the
Inspector and its ModifiedFormPages collection you can go from there to read
the controls on the form, VSTO or not.

If you want to handle events on that item once you have an object reference
you can only handle events for Outlook properties. So if your controls
aren't bound to Outlook props you are out of luck. You could handle the
Close and Write events (maybe also Send) on that item and check using
ModifiedFormPages as before to see the values.

Otherwise if the controls are bound to Outlook props you can use the
PropertyChange event, which passes the name of the property being changed or
the CustomPropertyChange event, which passes the name of the custom property
being changed.

To handle any of those, VSTO or not, you would add event handlers for any
events you want to trap.
 

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