Partager via


Extrait de code : action de code personnalisée

Dernière modification : vendredi 14 mai 2010

S’applique à : SharePoint Server 2010

L’exemple suivant illustre l’implémentation d’une action de code personnalisée.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.BusinessData.Runtime;
using System.Windows.Forms;
using outlookPIA = Microsoft.Office.Interop.Outlook;

namespace ContosoCustomer
{
    public class CustomCodeAction
    {
        //Custom Code Action Method
        //The parameters array contains the entity instance for current item as the first parameter.
        public void NewCustomVisitTask(object[] parameters)
        {
            IEntityInstance iei = parameters[0] as IEntityInstance;
            try
            {
                //Get values from current EntityInstance.
                string CustomerFName = iei["FirstName"].ToString();
                string CustomerLName = iei["LastName"].ToString();

                //Create a new Outlook task Item through Outlook interop.
                //Trusted Outlook interop object is set in CustomRibbonManger.
                outlookPIA.TaskItem newCustomVisitTaskItem =
                    (outlookPIA.TaskItem)CustomRibbonManger.currentOutlookApplication.CreateItem(outlookPIA.OlItemType.olTaskItem);

                //set task properties.
                newCustomVisitTaskItem.Subject = "Custom Visit Task: " + CustomerFName + " " + CustomerLName;
                newCustomVisitTaskItem.StartDate = DateTime.Now;
                newCustomVisitTaskItem.DueDate = DateTime.Now.AddDays(7);
                newCustomVisitTaskItem.Save();

                //Display task item.
                newCustomVisitTaskItem.Display(false);
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot find Entity Instance related to this item");
            }
        }
    }
}

Voir aussi

Référence

IEntityInstance