none
C++ how to add a hyperlink to MeetingItem? RRS feed

  • Question

  • I'm making a add-in for outlook, i can add hyperlink to AppointmentItem by using WordEditor,but when is add hyperlink to MeetingItem by the same method, it failed ,who can help me~~~~
    Tuesday, April 9, 2013 8:54 AM

Answers

All replies

  • How does it fail?  Do you get an error?  How are you accessing the MeetingItem, as they can't be created; you can only reference meeting requests received by a recipient.  Can you show your code?

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, April 9, 2013 4:06 PM
    Moderator
  • I'm using C++,my code:

    CComQIPtr<Outlook::_Inspector> spInspector;

    // the value of spMeetingItem is right

    HRESULT hr = spMeetingItem->get_GetInspector(&spInspector);
    if(SUCCEEDED(hr) && spInspector)
    {
    IDispatch* pDispWordEditor = NULL;
    hr = spInspector->get_WordEditor(&pDispWordEditor);

    if(SUCCEEDED(hr) && pDispWordEditor)
    {
    CComQIPtr<Word::_Document> spDocument;
    hr = pDispWordEditor->QueryInterface(__uuidof(_Document), (LPVOID*)&spDocument);
    if(SUCCEEDED(hr) && spDocument)
    {   
    VARIANT_BOOL varIsFound = VARIANT_FALSE;
    do
    {
    // get content of document
    CComQIPtr<Word::Range> spLinkRange;
    spDocument->get_Content(&spLinkRange);
    ATLASSERT(NULL != spLinkRange);

    CComQIPtr<Word::Find> spFind;
    spLinkRange->get_Find(&spFind);

    // set find properties and you needn't to see these
    BSTR bstrFind = (_bstr_t)lpctReplace;
    VARIANT varFindText;
    VARIANT_BOOL varFoward = VARIANT_TRUE;
    VARIANT_BOOL varFomat = VARIANT_FALSE;
    VARIANT_BOOL varMatchCase = VARIANT_FALSE;
    VARIANT_BOOL varMatchWholeWord = VARIANT_FALSE;
    VARIANT_BOOL varMatchWildcards = VARIANT_FALSE;
    VARIANT_BOOL varMatchSoundsLike = VARIANT_FALSE;
    VARIANT_BOOL varMatchAllWordForms = VARIANT_FALSE;

    spFind->put_Text(bstrFind);
    spFind->ClearFormatting();
    HRESULT Hresrult = spFind->Replacement->ClearFormatting();

    spFind->put_Forward(varFoward);
    spFind->put_Wrap(wdFindContinue);
    spFind->put_MatchCase(varMatchCase);
    spFind->put_MatchWholeWord(varMatchWholeWord);
    spFind->put_MatchWildcards(varMatchWildcards);
    spFind->put_MatchSoundsLike(varMatchSoundsLike);
    spFind->put_MatchAllWordForms(varMatchAllWordForms);

    varIsFound = spFind->Execute();
    if (varIsFound)
    {

    // find the word which need to changed as a hyperlink

    VARIANT content;
    content.vt = VT_BSTR;
    content.bstrVal = (_bstr_t)lpctLink;

    VARIANT display;
    display.vt = VT_BSTR;
    display.bstrVal = (_bstr_t)lpctShow;
    CComQIPtr<Word::Hyperlinks> spHyperlnks;
    spDocument->get_Hyperlinks(&spHyperlnks);
    CComQIPtr<Word::Hyperlink> spHyperlink;

    // Add hyperlink at here

    HRESULT hr = spHyperlnks->Add(spLinkRange, &content, NULL
    ,NULL, &display, &content);
    spMeetingItem->get_Body(&bstrBody);

    ........

    the value of 'hr' is S_FALSE,but when i add hyperlink to  AppointmentItem is successful by using the same method,and the value of hr is S_FALSE ,too. I don't know why...

    Wednesday, April 10, 2013 1:54 AM
  • I thought you were just setting HTML hyperlinks.  You may just be hitting some quirks of the Word Object Model inside a MeetingItem - which is usually not edited after it is sent.

    I can offer no further assistance - sorry.


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Wednesday, April 10, 2013 2:51 AM
    Moderator
  • Have you tried getting the associated appointment for the meeting item and using that instead?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Cappu893300" <=?utf-8?B?Q2FwcHU4OTMzMDA=?=> wrote in message news:c3a54003-c80a-4783-b7f3-a368bb950e93...

    I'm using C++,my code:

    CComQIPtr<Outlook::_Inspector> spInspector;

    // the value of spMeetingItem is right

    HRESULT hr = spMeetingItem->get_GetInspector(&spInspector);
    if(SUCCEEDED(hr) && spInspector)
    {
    IDispatch* pDispWordEditor = NULL;
    hr = spInspector->get_WordEditor(&pDispWordEditor);

    if(SUCCEEDED(hr) && pDispWordEditor)
    {
    CComQIPtr<Word::_Document> spDocument;
    hr = pDispWordEditor->QueryInterface(__uuidof(_Document), (LPVOID*)&spDocument);
    if(SUCCEEDED(hr) && spDocument)
    {   
    VARIANT_BOOL varIsFound = VARIANT_FALSE;
    do
    {
    // get content of document
    CComQIPtr<Word::Range> spLinkRange;
    spDocument->get_Content(&spLinkRange);
    ATLASSERT(NULL != spLinkRange);

    CComQIPtr<Word::Find> spFind;
    spLinkRange->get_Find(&spFind);

    // set find properties and you needn't to see these
    BSTR bstrFind = (_bstr_t)lpctReplace;
    VARIANT varFindText;
    VARIANT_BOOL varFoward = VARIANT_TRUE;
    VARIANT_BOOL varFomat = VARIANT_FALSE;
    VARIANT_BOOL varMatchCase = VARIANT_FALSE;
    VARIANT_BOOL varMatchWholeWord = VARIANT_FALSE;
    VARIANT_BOOL varMatchWildcards = VARIANT_FALSE;
    VARIANT_BOOL varMatchSoundsLike = VARIANT_FALSE;
    VARIANT_BOOL varMatchAllWordForms = VARIANT_FALSE;

    spFind->put_Text(bstrFind);
    spFind->ClearFormatting();
    HRESULT Hresrult = spFind->Replacement->ClearFormatting();

    spFind->put_Forward(varFoward);
    spFind->put_Wrap(wdFindContinue);
    spFind->put_MatchCase(varMatchCase);
    spFind->put_MatchWholeWord(varMatchWholeWord);
    spFind->put_MatchWildcards(varMatchWildcards);
    spFind->put_MatchSoundsLike(varMatchSoundsLike);
    spFind->put_MatchAllWordForms(varMatchAllWordForms);

    varIsFound = spFind->Execute();
    if (varIsFound)
    {

    // find the word which need to changed as a hyperlink

    VARIANT content;
    content.vt = VT_BSTR;
    content.bstrVal = (_bstr_t)lpctLink;

    VARIANT display;
    display.vt = VT_BSTR;
    display.bstrVal = (_bstr_t)lpctShow;
    CComQIPtr<Word::Hyperlinks> spHyperlnks;
    spDocument->get_Hyperlinks(&spHyperlnks);
    CComQIPtr<Word::Hyperlink> spHyperlink;

    // Add hyperlink at here

    HRESULT hr = spHyperlnks->Add(spLinkRange, &content, NULL
    ,NULL, &display, &content);
    spMeetingItem->get_Body(&bstrBody);

    ........

    the value of 'hr' is S_FALSE,but when i add hyperlink to  AppointmentItem is successful by using the same method,and the value of hr is S_FALSE ,too. I don't know why...


    Ken Slovak MVP - Outlook
    Wednesday, April 10, 2013 4:24 PM
    Moderator
  • first,thank you for your answer

    I'v tried your solution,but i need to make the add-in like these:

    the template of addresser is A,and the template of recipients is B. Template A made of appointItem and Template B made of meetingItem,Template A is different from Template B.

    As you said, i used appointItem,i add hyperlink successful.But i need to put Two Different Template,If i used appointItem,how can i put Two Different Template?so,can you give me a good idea?

    Thank you again~

    Thursday, April 11, 2013 2:34 AM
  • Thank you all the same~~
    Thursday, April 11, 2013 2:37 AM
  • there is already thread with the same problem http://social.msdn.microsoft.com/Forums/en-US/outlookdev/thread/807ec173-51f7-4b7a-8882-01b4b0f26b86. Apparently wordAPI fails on meeting requests for some reason.
    Thursday, April 11, 2013 10:13 AM
  • I'm confused with the different templates. Only 1 appointment item can be associated with a meeting item. If you call GetAssociatedAppointment() on a meeting you will get the appointment associated with that meeting. You should then be able to use all the normal methods of adding things to the body of the appointment item.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Cappu893300" <=?utf-8?B?Q2FwcHU4OTMzMDA=?=> wrote in message news:f2694fd3-650f-4a7c-bc59-221279230297...

    first,thank you for your answer

    I'v tried your solution,but i need to make the add-in like these:

    the template of addresser is A,and the template of recipients is B. Template A made of appointItem and Template B made of meetingItem,Template A is different from Template B.

    As you said, i used appointItem,i add hyperlink successful.But i need to put Two Different Template,If i used appointItem,how can i put Two Different Template?so,can you give me a good idea?

    Thank you again~


    Ken Slovak MVP - Outlook
    Thursday, April 11, 2013 2:35 PM
    Moderator
  • Apparently calling Activate on inspector for meeting request is required to make it work, Can you verify that?
    Thursday, April 11, 2013 4:56 PM
  • Verify what, specifically? So many things have been discussed in this thread and the thread you linked to that I'm not sure what you want verified.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:ac0a9fd2-c83a-4f62-946c-96f308dc52e2...
    Apparently calling Activate on inspector for meeting request is required to make it work, Can you verify that?

    Ken Slovak MVP - Outlook
    Thursday, April 11, 2013 9:10 PM
    Moderator
  • Sorry Ken, i was asking Cappu to verify if calling Activate on Inspector solves the issue for meeting request
    Friday, April 12, 2013 4:18 AM
  • Dear Damian,

    i'v already add a hyperlink to meetingitem,but folowing anothor question:the hyperlink always add "file://",

    such as,"file://http://www.google.com".

    Friday, April 12, 2013 6:16 AM
  • Dear Ken,

    i'v already add a hyperlink to meetingitem,but folowing anothor question:the hyperlink always add "file://",

    such as,"file://http://www.google.com".

    Friday, April 12, 2013 6:17 AM
  • i do not think this is word's doing - what are the contents of lpctLink variable?
    Friday, April 12, 2013 8:12 AM
  • I've never seen that.
     
    If I add a hyperlink to an open meeting request I can run the following Outlook VBA code:
     
    Sub WordMailMeeting()
        Dim w As Word.document
        Set w = Application.ActiveInspector.WordEditor
        Debug.Print w.Range
        Debug.Print w.Hyperlinks(1).TextToDisplay
        Debug.Print w.Hyperlinks(1).Range
    End Sub
     
    I then get these results in the Immediate window:
     
    I do not see any file URL.
     
    Here's what the HTML equivalent for the body of the meeting looks like in OutlookSpy when looking at the PR_HTML property of the IMessage:
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    <META NAME="Generator" CONTENT="MS Exchange Server version 14.02.5004.000">
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <!-- Converted from text/rtf format -->
     
    <P DIR=LTR><SPAN LANG="en-us"></SPAN><A HREF="http://www.slovaktech.com"><SPAN LANG="en-us"><U><FONT COLOR="#0000FF" FACE="Calibri">http://www.slovaktech.com</FONT></U></SPAN><SPAN LANG="en-us"></SPAN></A><SPAN LANG="en-us"></SPAN></P>
     
    <P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
     
    </BODY>
    </HTML>

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Cappu893300" <=?utf-8?B?Q2FwcHU4OTMzMDA=?=> wrote in message news:0a653083-ba4f-44eb-931b-4f707f468024...

    Dear Ken,

    i'v already add a hyperlink to meetingitem,but folowing anothor question:the hyperlink always add "file://",

    such as,"file://http://www.google.com".


    Ken Slovak MVP - Outlook
    Friday, April 12, 2013 2:49 PM
    Moderator
  • Thank for your answer~

    I found the reasion,Because of there is a space after the link...

    Monday, April 15, 2013 3:43 AM
  • Thank for your answer~

    I found the reasion,Because of there is a space after the link...
    Monday, April 15, 2013 3:44 AM