Save a Form Region Content

M

morna

I have created a form region from a IPM.Appointment item and have my
new item on the Actions menu "New MS Event". Two things...when I
select "New MS Event" in a calendar I am presented with the new form
region that I created. I populate all the fields on the form region
and the select "Save" button on the Ribbon. When I select open again
on the item I saved the fields on the form region are not populated.
I have this built within a VSTO addin and I can catch the
FormRegion_FormRegionClosed(..) event.. should I be saving the content
of this form region or should Outlook be saving the content? Does
anyone have a code example?

Also - I would like to put a "MS Event" commandbar on the content menu
when a user right clicks on the calendar - I have a commandbar
included there, however don't know what to put in the event handler to
make the new form region to appear...anyone got any thoughts?

Thanks for your time.
-Morna
 
S

Sue Mosher [MVP-Outlook]

VS 2008 or VSTO 2005 SE? If 2008, did you create the region in the designer or import an .ofs file?

To create a new instance of a custom form programmatically, use the Add method on the target folder's Items collection:

newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
newItem.Display

If the target is a default folder, you can use the Namespace.GetDefaultFolder method to return it as a Folder object.
 
M

morna

VS 2008 or VSTO 2005 SE? If 2008, did you create the region in the designer or import an .ofs file?

To create a new instance of a custom form programmatically, use the Add method on the target folder's Items collection:

    newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
    newItem.Display

If the target is a default folder, you can use the Namespace.GetDefaultFolder method to return it as a Folder object.

--
Sue Mosher, Outlook MVP
   Author of Microsoft Outlook 2007 Programming:
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54







- Show quoted text -

Hey Sue -

I used VS 2008 and I did create the region in the designer?

How can I get a hook to the FormRegion.cs object from the ThisAddin
class? Also... when a user selects the "Save" on the ribbon of the
FormRegion can I catch this event in my addin?
I can create a new appointment item on the fly if I can catch the save
event and the use UserProperties to save fields that are not really in
the IPM.Appointment object and save them to the MS Event folder if I
can catch the "Save" event that fires when a user selects the "Save"
on the ribbon of the FormRegion... just thinking out loud.

Thanks so much for your time.

-Morna
 
S

Sue Mosher [MVP-Outlook]

I used VS 2008 and I did create the region in the designer?

In that case, you will have to write code to set the values of the Outlook properties where you want the region's control data to be stored. You could avoid that by creating the region in the Outlook designer and importing it instead of using the VS 2008 designer.
Also... when a user selects the "Save" on the ribbon of the FormRegion can I catch this event in my addin?

When the user opens the item (Inspectors.NewInspector, followed by Inspector.Activate), you can subscribe to the AppointmentItem.Save event. However, I'm not sure whether it's better to use Activate or use one of the form region events. Might take some experimenting.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


VS 2008 or VSTO 2005 SE? If 2008, did you create the region in the designer or import an .ofs file?

To create a new instance of a custom form programmatically, use the Add method on the target folder's Items collection:

newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
newItem.Display

If the target is a default folder, you can use the Namespace.GetDefaultFolder method to return it as a Folder object.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54







- Show quoted text -

Hey Sue -

I used VS 2008 and I did create the region in the designer?

How can I get a hook to the FormRegion.cs object from the ThisAddin
class? Also... when a user selects the "Save" on the ribbon of the
FormRegion can I catch this event in my addin?
I can create a new appointment item on the fly if I can catch the save
event and the use UserProperties to save fields that are not really in
the IPM.Appointment object and save them to the MS Event folder if I
can catch the "Save" event that fires when a user selects the "Save"
on the ribbon of the FormRegion... just thinking out loud.

Thanks so much for your time.

-Morna
 
M

morna

VS 2008 or VSTO 2005 SE? If 2008, did you create the region in the designer or import an .ofs file?

To create a new instance of a custom form programmatically, use the Add method on the target folder's Items collection:

    newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
    newItem.Display

If the target is a default folder, you can use the Namespace.GetDefaultFolder method to return it as a Folder object.

--
Sue Mosher, Outlook MVP
   Author of Microsoft Outlook 2007 Programming:
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54







- Show quoted text -

Hey Sue..

The following works well:

newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
newItem.Display

and I hooked this up to my "New MS Event" on the right click content
menu.

However, when I select the "Save" on the ribbon for this item is never
saved to the calendar. When I select the "New MS Event" from the
Actions menu, the item gets saved to the calendar. Have I missed
something here...or is it another one of those Outlook dark secret
things :)

-Morna
 
S

Sue Mosher [MVP-Outlook]

How are you instantiating the targetFolder object?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


VS 2008 or VSTO 2005 SE? If 2008, did you create the region in the designer or import an .ofs file?

To create a new instance of a custom form programmatically, use the Add method on the target folder's Items collection:

newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
newItem.Display

If the target is a default folder, you can use the Namespace.GetDefaultFolder method to return it as a Folder object.

The following works well:

newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
newItem.Display

and I hooked this up to my "New MS Event" on the right click content
menu.

However, when I select the "Save" on the ribbon for this item is never
saved to the calendar. When I select the "New MS Event" from the
Actions menu, the item gets saved to the calendar. Have I missed
something here...or is it another one of those Outlook dark secret
things :)

-Morna
 
M

morna

How are you instantiating the targetFolder object?

--
Sue Mosher, Outlook MVP
   Author of Microsoft Outlook 2007 Programming:
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54








The following works well:

 newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
    newItem.Display

and I hooked this up to my "New MS Event" on the right click content
menu.

However, when I select the "Save" on the ribbon for this item is never
saved to the calendar.  When I select the "New MS Event" from the
Actions menu, the item gets saved to the calendar.  Have I missed
something here...or is it another one of those Outlook dark secret
things :)

-Morna- Hide quoted text -

- Show quoted text -

Hey Sue & all,

Here is the code that handles the CommandBar event OnUpdate - this
function is in the ThisAddin.cs file:

/// <summary>
/// This function handles the click event of the "New MS
Event" button on the context menu.
/// </summary>
/// <param name="btn"></param>
/// <param name="cancel"></param>
public void newButton_Click(Office.CommandBarButton btn, ref
bool cancel)
{
try
{
// get the MS Event calendar folder
Microsoft.Office.Interop.Outlook.MAPIFolder Calendar =
m_applicationObject.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder msEventFolder =
Calendar.Folders["MS Event"];

// creates a new IPM.Appointment.Event object to store
the form region content
Outlook.AppointmentItem newItem =
(Outlook.AppointmentItem)msEventFolder.Items.Add("IPM.Appointment.Event");
// displays the MS Event region form
newItem.Display(false);
}
catch (Exception ex)
{
Utilities.Log.WriteToLog(m_EventLogName,
"newButton_Click() err: " + ex.Message,
System.Diagnostics.EventLogEntryType.Error);
}
}

so... I am getting the Calendar collections of folders and then
looking for the "MS Event" calendar folder. at that point I use the
code you suggested... it creates a MS Event form for me, however, on
the save (see code below in the MSEventRegion.cs file - I could not
find a "Save" event on the Outlook.AppointmentItem - so I used the
Item_Write event) it does not save the item to the MS Event calendar.

// Outlook application object
private Outlook.Application m_applicationObject;
private Outlook.AppointmentItem Item;

// Occurs before the form region is displayed.
// Use this.OutlookItem to get a reference to the current
Outlook item.
// Use this.OutlookFormRegion to get a reference to the form
region.
private void FormRegion_FormRegionShowing(object sender,
System.EventArgs e)
{
m_applicationObject = new Outlook.Application();

Item = this.OutlookItem as Outlook.AppointmentItem;
Item.Write += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_WriteEventHandler(Item_Write);
}

/// <summary>
/// This function handles the save event of the MS Event
object
/// </summary>
/// <param name="Cancel"></param>
public void Item_Write(ref bool Cancel)
{
try
{
SaveAppointment();
Cancel = false;

if (Item != null)
Item = null;
}
catch (Exception ex)
{
Utilities.Log.WriteToLog("FormRegion.Item_Write(..)
err: " + ex.Message, System.Diagnostics.EventLogEntryType.Error);
}
}

// Occurs when the form region is closed.
// Use this.OutlookItem to get a reference to the current
Outlook item.
// Use this.OutlookFormRegion to get a reference to the form
region.
private void FormRegion_FormRegionClosed(object sender,
System.EventArgs e)
{
MessageBox.Show("Form Closed");
}

/// <summary>
/// This function saves the MSEvent object in a
IPM.Appointment item
/// </summary>
private void SaveAppointment()
{
try
{
// get the MS Event folder
Microsoft.Office.Interop.Outlook.MAPIFolder Calendar =
m_applicationObject.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder msEventFolder =
Calendar.Folders["MS Event"];

if( msEventFolder != null )
{
Outlook.AppointmentItem appointmentItem =
(Outlook.AppointmentItem)m_applicationObject.CreateItem(Outlook.OlItemType.olAppointmentItem);
AddUserPropToAppointment(appointmentItem);

appointmentItem.Subject = this.TextBoxName.Text;
appointmentItem.Start =
this.DatePickerStartDate.Value;
appointmentItem.End =
this.DatePickerEndDate.Value;
appointmentItem.Location =
this.TextBoxLocation.Text;

appointmentItem.UserProperties["Description"].Value =
this.TextBoxDescription.Text;
if(this.ComboBoxType.SelectedItem != null)
appointmentItem.UserProperties["Type"].Value =
this.ComboBoxType.SelectedItem.ToString();
appointmentItem.UserProperties["KeySpeaker"].Value
= this.TextBoxKeySpeaker.Text;

appointmentItem.UserProperties["MSEventWebsite"].Value =
this.TextBoxWebsite.Text;
appointmentItem.UserProperties["Attendance"].Value
= this.TextBoxEstAttendance.Text;
appointmentItem.UserProperties["BusOwner"].Value =
this.TextBoxBusOwner.Text;
}
}
catch(Exception ex)
{
Utilities.Log.WriteToLog("SaveAppointment() err: " +
ex.Message, System.Diagnostics.EventLogEntryType.Error);
}
}

/// <summary>
/// This function creates the custom user fields that will
allow for storage of an MSEvent object in a IPM.Appointment item
/// </summary>
/// <param name="appointmentItem"></param>
private void AddUserPropToAppointment(Outlook.AppointmentItem
appointmentItem)
{
try
{
appointmentItem.UserProperties.Add("Description",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("Type",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("KeySpeaker",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("MSEventWebsite",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("Attendance",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("BusOwner",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
}
catch (Exception ex)
{
Utilities.Log.WriteToLog("AddUserPropToAppointment(..)
err: " + ex.Message, System.Diagnostics.EventLogEntryType.Error);
}
}
 
S

Sue Mosher [MVP-Outlook]

This statement returns the item displayed:

Outlook.AppointmentItem newItem =
(Outlook.AppointmentItem)msEventFolder.Items.Add("IPM.Appointment.Event");

Therefore, you should be subscribing to the Write event of that newItem object. Note, however, that unless the user (or your code) changes an actual Outlook property, the item will not be saved and Write will not fire.

I had a hard time following the rest of your code logic, and it's not just because I read C# only a little. It looks to me like you are creating new appointments in FormRegionShowing and SaveAppointment rather than working with the item (newItem) that is already displayed.

In any case, if your only goal in using a form region is to get the user to enter data into OUtlook properties, I would strongly suggest that you build the region in Outlook's designer rather than VS2008's and save yourself a lot of coding time.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


How are you instantiating the targetFolder object?








The following works well:

newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
newItem.Display

and I hooked this up to my "New MS Event" on the right click content
menu.

However, when I select the "Save" on the ribbon for this item is never
saved to the calendar. When I select the "New MS Event" from the
Actions menu, the item gets saved to the calendar. Have I missed
something here...or is it another one of those Outlook dark secret
things :)

Hey Sue & all,

Here is the code that handles the CommandBar event OnUpdate - this
function is in the ThisAddin.cs file:

/// <summary>
/// This function handles the click event of the "New MS
Event" button on the context menu.
/// </summary>
/// <param name="btn"></param>
/// <param name="cancel"></param>
public void newButton_Click(Office.CommandBarButton btn, ref
bool cancel)
{
try
{
// get the MS Event calendar folder
Microsoft.Office.Interop.Outlook.MAPIFolder Calendar =
m_applicationObject.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder msEventFolder =
Calendar.Folders["MS Event"];

// creates a new IPM.Appointment.Event object to store
the form region content
Outlook.AppointmentItem newItem =
(Outlook.AppointmentItem)msEventFolder.Items.Add("IPM.Appointment.Event");
// displays the MS Event region form
newItem.Display(false);
}
catch (Exception ex)
{
Utilities.Log.WriteToLog(m_EventLogName,
"newButton_Click() err: " + ex.Message,
System.Diagnostics.EventLogEntryType.Error);
}
}

so... I am getting the Calendar collections of folders and then
looking for the "MS Event" calendar folder. at that point I use the
code you suggested... it creates a MS Event form for me, however, on
the save (see code below in the MSEventRegion.cs file - I could not
find a "Save" event on the Outlook.AppointmentItem - so I used the
Item_Write event) it does not save the item to the MS Event calendar.

// Outlook application object
private Outlook.Application m_applicationObject;
private Outlook.AppointmentItem Item;

// Occurs before the form region is displayed.
// Use this.OutlookItem to get a reference to the current
Outlook item.
// Use this.OutlookFormRegion to get a reference to the form
region.
private void FormRegion_FormRegionShowing(object sender,
System.EventArgs e)
{
m_applicationObject = new Outlook.Application();

Item = this.OutlookItem as Outlook.AppointmentItem;
Item.Write += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_WriteEventHandler(Item_Write);
}

/// <summary>
/// This function handles the save event of the MS Event
object
/// </summary>
/// <param name="Cancel"></param>
public void Item_Write(ref bool Cancel)
{
try
{
SaveAppointment();
Cancel = false;

if (Item != null)
Item = null;
}
catch (Exception ex)
{
Utilities.Log.WriteToLog("FormRegion.Item_Write(..)
err: " + ex.Message, System.Diagnostics.EventLogEntryType.Error);
}
}

// Occurs when the form region is closed.
// Use this.OutlookItem to get a reference to the current
Outlook item.
// Use this.OutlookFormRegion to get a reference to the form
region.
private void FormRegion_FormRegionClosed(object sender,
System.EventArgs e)
{
MessageBox.Show("Form Closed");
}

/// <summary>
/// This function saves the MSEvent object in a
IPM.Appointment item
/// </summary>
private void SaveAppointment()
{
try
{
// get the MS Event folder
Microsoft.Office.Interop.Outlook.MAPIFolder Calendar =
m_applicationObject.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder msEventFolder =
Calendar.Folders["MS Event"];

if( msEventFolder != null )
{
Outlook.AppointmentItem appointmentItem =
(Outlook.AppointmentItem)m_applicationObject.CreateItem(Outlook.OlItemType.olAppointmentItem);
AddUserPropToAppointment(appointmentItem);

appointmentItem.Subject = this.TextBoxName.Text;
appointmentItem.Start =
this.DatePickerStartDate.Value;
appointmentItem.End =
this.DatePickerEndDate.Value;
appointmentItem.Location =
this.TextBoxLocation.Text;

appointmentItem.UserProperties["Description"].Value =
this.TextBoxDescription.Text;
if(this.ComboBoxType.SelectedItem != null)
appointmentItem.UserProperties["Type"].Value =
this.ComboBoxType.SelectedItem.ToString();
appointmentItem.UserProperties["KeySpeaker"].Value
= this.TextBoxKeySpeaker.Text;

appointmentItem.UserProperties["MSEventWebsite"].Value =
this.TextBoxWebsite.Text;
appointmentItem.UserProperties["Attendance"].Value
= this.TextBoxEstAttendance.Text;
appointmentItem.UserProperties["BusOwner"].Value =
this.TextBoxBusOwner.Text;
}
}
catch(Exception ex)
{
Utilities.Log.WriteToLog("SaveAppointment() err: " +
ex.Message, System.Diagnostics.EventLogEntryType.Error);
}
}

/// <summary>
/// This function creates the custom user fields that will
allow for storage of an MSEvent object in a IPM.Appointment item
/// </summary>
/// <param name="appointmentItem"></param>
private void AddUserPropToAppointment(Outlook.AppointmentItem
appointmentItem)
{
try
{
appointmentItem.UserProperties.Add("Description",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("Type",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("KeySpeaker",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("MSEventWebsite",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("Attendance",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
appointmentItem.UserProperties.Add("BusOwner",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
}
catch (Exception ex)
{
Utilities.Log.WriteToLog("AddUserPropToAppointment(..)
err: " + ex.Message, System.Diagnostics.EventLogEntryType.Error);
}
}
 
M

morna

This statement returns the item displayed:

Outlook.AppointmentItem newItem =
(Outlook.AppointmentItem)msEventFolder.Items.Add("IPM.Appointment.Event");

Therefore, you should be subscribing to the Write event of that newItem object. Note, however, that unless the user (or your code) changes an actual Outlook property, the item will not be saved and Write will not fire.

I had a hard time following the rest of your code logic, and it's not justbecause I read C# only a little. It looks to me like you are creating new appointments in FormRegionShowing and SaveAppointment rather than working with the item (newItem) that is already displayed.

In any case, if your only goal in using a form region is to get the user to enter data into OUtlook properties, I would strongly suggest that you build the region in Outlook's designer rather than VS2008's and save yourself a lot of coding time.

--
Sue Mosher, Outlook MVP
   Author of Microsoft Outlook 2007 Programming:
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54


How are you instantiating the targetFolder object?
The following works well:
newItem = targetFolder.Items.Add("IPM.Appointment.MS Event")
newItem.Display
and I hooked this up to my "New MS Event" on the right click content
menu.
However, when I select the "Save" on the ribbon for this item is never
saved to the calendar. When I select the "New MS Event" from the
Actions menu, the item gets saved to the calendar. Have I missed
something here...or is it another one of those Outlook dark secret
things :)

Hey Sue & all,

Here is the code that handles the CommandBar event OnUpdate - this
function is in the ThisAddin.cs file:

        /// <summary>
        /// This function handles the click event of the "New MS
Event" button on the context menu.
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="cancel"></param>
        public void newButton_Click(Office.CommandBarButton btn, ref
bool cancel)
        {
            try
            {
                // get the MS Event calendar folder
                Microsoft.Office.Interop.Outlook.MAPIFolder Calendar =
m_applicationObject.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office..­Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.MAPIFolder msEventFolder =
Calendar.Folders["MS Event"];

                // creates a new IPM.Appointment.Event object to store
the form region content
                Outlook.AppointmentItem newItem =
(Outlook.AppointmentItem)msEventFolder.Items.Add("IPM.Appointment.Event");
                // displays the MS Event region form
                newItem.Display(false);
            }
            catch (Exception ex)
            {
                Utilities.Log.WriteToLog(m_EventLogName,
"newButton_Click() err: " + ex.Message,
System.Diagnostics.EventLogEntryType.Error);
            }
        }

so... I am getting the Calendar collections of folders and then
looking for the "MS Event" calendar folder.  at that point I use the
code you suggested... it creates a MS Event form for me, however, on
the save (see code below in the MSEventRegion.cs file - I could not
find a "Save" event on the Outlook.AppointmentItem - so I used the
Item_Write event) it does not save the item to the MS Event calendar.

        // Outlook application object
        private Outlook.Application m_applicationObject;
        private Outlook.AppointmentItem Item;

        // Occurs before the form region is displayed.
        // Use this.OutlookItem to get a reference to the current
Outlook item.
        // Use this.OutlookFormRegion to get a reference to the form
region.
        private void FormRegion_FormRegionShowing(object sender,
System.EventArgs e)
        {
            m_applicationObject = new Outlook.Application();

            Item = this.OutlookItem as Outlook.AppointmentItem;
            Item.Write += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_WriteEventHandler(Item_Write­);
        }

        /// <summary>
        /// This function handles the save event of the MS Event
object
        /// </summary>
        /// <param name="Cancel"></param>
        public void Item_Write(ref bool Cancel)
        {
            try
            {
                SaveAppointment();
                Cancel = false;

                if (Item != null)
                    Item = null;
            }
            catch (Exception ex)
            {
                Utilities.Log.WriteToLog("FormRegion.Item_Write(..)
err: " + ex.Message, System.Diagnostics.EventLogEntryType.Error);
            }
        }

        // Occurs when the form region is closed.
        // Use this.OutlookItem to get a reference to the current
Outlook item.
        // Use this.OutlookFormRegion to get a reference to the form
region.
        private void FormRegion_FormRegionClosed(object sender,
System.EventArgs e)
        {
            MessageBox.Show("Form Closed");
        }

        /// <summary>
        /// This function saves the MSEvent object in a
IPM.Appointment item
        /// </summary>
        private void SaveAppointment()
        {
            try
            {
                // get the MS Event folder
                Microsoft.Office.Interop.Outlook.MAPIFolder Calendar =
m_applicationObject.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office..­Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.MAPIFolder msEventFolder =
Calendar.Folders["MS Event"];

                if( msEventFolder != null )
                {
                    Outlook.AppointmentItem appointmentItem =
(Outlook.AppointmentItem)m_applicationObject.CreateItem(Outlook.OlItemType..­olAppointmentItem);
                    AddUserPropToAppointment(appointmentItem);

                    appointmentItem.Subject = this.TextBoxName.Text;
                    appointmentItem.Start =
this.DatePickerStartDate.Value;
                    appointmentItem.End =
this.DatePickerEndDate.Value;
                    appointmentItem.Location =
this.TextBoxLocation.Text;

appointmentItem.UserProperties["Description"].Value =
this.TextBoxDescription.Text;
                    if(this.ComboBoxType.SelectedItem != null)
                        appointmentItem.UserProperties["Type"].Value =
this.ComboBoxType.SelectedItem.ToString();
                    appointmentItem.UserProperties["KeySpeaker"].Value
= this.TextBoxKeySpeaker.Text;

appointmentItem.UserProperties["MSEventWebsite"].Value =
this.TextBoxWebsite.Text;
                    appointmentItem.UserProperties["Attendance"].Value
= this.TextBoxEstAttendance.Text;
                    appointmentItem.UserProperties["BusOwner"].Value =
this.TextBoxBusOwner.Text;
                }
            }
            catch(Exception ex)
            {
                Utilities.Log.WriteToLog("SaveAppointment() err: " +
ex.Message, System.Diagnostics.EventLogEntryType.Error);
            }
        }

        /// <summary>
        /// This function creates the custom user fields that will
allow for storage of an MSEvent object in a IPM.Appointment item
        /// </summary>
        /// <param name="appointmentItem"></param>
        private void AddUserPropToAppointment(Outlook.AppointmentItem
appointmentItem)
        {
            try
            {
                appointmentItem.UserProperties.Add("Description",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
                appointmentItem.UserProperties.Add("Type",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
                appointmentItem.UserProperties.Add("KeySpeaker",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
                appointmentItem.UserProperties.Add("MSEventWebsite",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
                appointmentItem.UserProperties.Add("Attendance",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
                appointmentItem.UserProperties.Add("BusOwner",
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false,
System.Reflection.Missing.Value);
            }
            catch (Exception ex)
            {
                Utilities.Log.WriteToLog("AddUserPropToAppointment(..)
err: " + ex.Message, System.Diagnostics.EventLogEntryType.Error);
            }
        }- Hide quoted text -

- Show quoted text -

Hey Sue & all,

My problem here is I did build the form region through Outlook
designer and I have an MSEvent.ofs file for the form, however, I have
never been able to work throught the load process for the form to get
it to display in Outlook. I have issues with the manifest.xml file
and the regedit enters. I even purchased a book "Professional Outlook
2007 Programming" by Ken Slovak. I look hard at your book "Outlook
2007 Programming" but the editior's comments and your comments on
Amazon said it was not really for programming more for
administration. Can you point me in a direction - a website or a book
that outlines loading a *.ofs file into an addin and working with the
saved content of the form....I reviewed several other books that
perhaps would cover the form regions, however, have found nothing that
could really help get this up and running.

Thank you so much for your time.

-Morna
 
S

Sue Mosher [MVP-Outlook]

There are two issues here -- design of the region and loading it in the add-in. The loading for VS2008 is covered in the MSDN article at http://msdn2.microsoft.com/en-us/library/bb608611.aspx

The critical issue in the design is that each control that you want to use for entering data to be stored permanently needs to be bound to an Outlook property. Do that on the Value tab of each control's properties dialog, in the Outlook designer. Once you do that, data that the user types into the region's controls will automatically be saved with the item. In other words, no code will be needed to add properties or save the item.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54



My problem here is I did build the form region through Outlook
designer and I have an MSEvent.ofs file for the form, however, I have
never been able to work throught the load process for the form to get
it to display in Outlook. I have issues with the manifest.xml file
and the regedit enters. I even purchased a book "Professional Outlook
2007 Programming" by Ken Slovak. I look hard at your book "Outlook
2007 Programming" but the editior's comments and your comments on
Amazon said it was not really for programming more for
administration. Can you point me in a direction - a website or a book
that outlines loading a *.ofs file into an addin and working with the
saved content of the form....I reviewed several other books that
perhaps would cover the form regions, however, have found nothing that
could really help get this up and running.
 

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