none
Hyperlink in outlook appointment item c#,Adding another link at particular position. RRS feed

  • Question

  • Hi All,

    I have added following code to my outlook addin(C#) ,to create appointment item and added hyperlink to it ,but I want to add hyperlink to middle of the appointment item currently it is appending at the last.

    Also I want to add one more link in the appointment item,but I am new to this.

    Any ideas? Help?

    Here is my code snippet:

     Microsoft.Office.Interop.Word.Document document = (Microsoft.Office.Interop.Word.Document)appItem.GetInspector.WordEditor;


     document.Content.Select();
     object direct = Microsoft.Office.Interop.Word.WdMovementType.wdMove;
     document.Application.Selection.Collapse(ref direct);

     if ((document.Content.Text == null) || (document.Content.Text == "\r"))
      {
          document.Application.Selection.Range.Text = appItem.Body;
       }
     else
       {
         document.Application.Selection.Range.Text = "\n\nTo join the meeting now, click here: ";
        }

      object missing = Type.Missing;
      object strLinkURL = MeetingLink;
      object strLinkText = CreateMeetingDlg.MeetingName;
      document.Content.Select();
      document.Application.Selection.Collapse(ref direct);
      document.Content.Hyperlinks.Add(document.Application.Selection.Range, ref strLinkURL, ref missing, ref    missing, ref strLinkText, ref missing);

       appItem.Start = Convert.ToDateTime(DateTime.Now);
       appItem.End = Convert.ToDateTime(DateTime.Now.AddMinutes(30));
       appItem.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
       appItem.Display(true);
                         appItem.GetInspector.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olPromptForSave);
      Marshal.ReleaseComObject(appItem);
      GC.Collect();

    I shall be thankful for an early reply.

    Regards,

    Suraj Shaha.


    Suraj


    • Edited by Suraj Shaha Tuesday, January 8, 2013 1:06 PM Cleared the bug.
    Tuesday, January 8, 2013 1:05 PM

Answers

  • you should release every COM object that you get, not just appointmentitem, so Inspector that you get from GetInspector call and Document object also. Of course there is no guarantee that your problem will go away since there are other parts of your code where you could have create multiple references to those objects.
    Tuesday, January 8, 2013 2:12 PM

All replies

  • code does exactly what you want - appends link to the end - if you want to add it somewhere in the 'middle', then you have to change your code to take that into account. It is up to you to decide what 'middle' means for your business logic.
    Tuesday, January 8, 2013 1:09 PM
  • Hi DamianD,

    Thanks for your reply.I just want to know from  above code snippet:

    If I removed gc.collect() from the code then appointment item is not closed properly i.e we need to close it twice.

    why this could be happening?

    How to handle closing of appitem and its inspector and olpromptsave condition.

    Regards,

    Suraj


    Suraj

    Tuesday, January 8, 2013 1:24 PM
  • you should release every COM object that you get, not just appointmentitem, so Inspector that you get from GetInspector call and Document object also. Of course there is no guarantee that your problem will go away since there are other parts of your code where you could have create multiple references to those objects.
    Tuesday, January 8, 2013 2:12 PM