如果我发送约会而不在代码中显示它,则使用剪贴板粘贴RTF文本无效

时间:2013-02-01 06:42:49

标签: c# outlook

我正在开发visual studio 2010和c sharp的应用程序。在这个应用程序中,我正在创建一个约会项目,通过word doc粘贴约会正文中的一些RTF文本并发送它。以下是我的代码的一部分:

  public void SetAppointmentBodyViaWordDoc(ref Outlook.AppointmentItem appointment, string rtfText)

{            Outlook.Inspector inspector = null;             尝试             {                 //appointment.Body = string.Empty;                 System.Windows.Forms.DataObject dataObject = new System.Windows.Forms.DataObject();                 dataObject.SetData(DataFormats.Rtf,rtfText);                 System.Windows.Forms.Clipboard.Clear();                 System.Windows.Forms.Clipboard.SetDataObject(dataObject,false,10,200);                 inspector = appointment.GetInspector;                 Word.Document appointmentItemDocument = inspector.WordEditor as Word.Document;                 appointmentItemDocument.Application.ScreenUpdating = false;                 foreach(在appointmentItemDocument.Windows中的Word.Window窗口)                 {                     window.Selection.WholeStory();                     window.Selection.TypeBackspace();                     window.Selection.Paste();

                //move the cursor to the top
                object story = Word.WdUnits.wdStory;
                object missing = Missing.Value;
                window.Selection.HomeKey(ref story, ref missing);
                break;
            }
            appointmentItemDocument.Application.ScreenUpdating = true;
        }
        catch (System.Exception ex)
        {
                System.Windows.Forms.MessageBox.Show("Exception in SetAppointmentBodyViaWordDoc(): " + System.Environment.NewLine +
                    ex.ToString());
        }
        finally
        {
            if (inspector != null) Marshal.ReleaseComObject(inspector);
        }

}

当我调用appointment.Display()然后它完美地工作,我可以看到并发送带有粘贴文本的约会。但是如果我使用appointment.Send()方法在Code中发送约会而不显示约会那么它在身体中没有粘贴文本而收件人获取空体。我需要发送它而不显示约会。如果有人对此问题有任何疑问,请告诉我。

非常感谢,

苏里亚

1 个答案:

答案 0 :(得分:0)

为什么不简单地设置AppointmeentItem.RtfBody属性?