none
Outlook Add-in: export a contact to a .vcf file RRS feed

  • Question

  • I would like to be able to save a contact to a .vcf file programmatically. However, when I get a hold of the contact item and call "SaveAs" and use the .vcf file extenstion, the resulting file shows a blank contact when I open it. When I give the same file a .msg extension it opens and shows all the contact information properly, but I need the file to have a .vcf extension so that it can be imported back into outlook.
    Saturday, January 21, 2017 2:53 AM

Answers

  • If you do not specify the format (second optional parameter), Outlook assumes MSG format. You must explicitly specify the vCard format. Outlook does not look at the extension of the file name to figure out what it is exactly that you want.

    {
    	contactItem.SaveAs( "C:\\Users\\username\\Desktop\\" + request.FirstName + request.LastName + ".vcf", OlSaveAsType.olVCard);
    }


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Monday, January 23, 2017 9:59 PM

All replies

  • Please show your code.

    Have you tried to open the VCF fiel in Notepad?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Saturday, January 21, 2017 6:15 PM
  • Hello Jeremy,

    What value did you pass as the second argument to the SaveAs method of the ContactItem class?


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Saturday, January 21, 2017 8:17 PM
  • Hi Jeremy at Black Mountain,

    I can see that you only describe your problem but did not post a code having the issue.

    without code we are not able to suggest you a solution as we are not aware with the code you are using.

    it is better if you post a sample code. so that we can try to look in to that and try to provide you a helpful suggestion.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 23, 2017 3:06 AM
    Moderator
  • contactItem = folderItems.Find( $"[FirstName]='{request.FirstName}' and [LastName]='{request.LastName}'" );
    if( contactItem != null )
    {
    	contactItem.SaveAs( "C:\\Users\\username\\Desktop\\" + request.FirstName + request.LastName + ".msg" );
    }
    I have not tried opening in notepad.
    Monday, January 23, 2017 6:50 PM
  • Hi Eugene,

    I did not pass in a 2nd argument as I am not sure which object type to specify.

    Monday, January 23, 2017 6:55 PM
  • Hi Deepak, thank youfor the reply. My code that tries to save the file as a .vcf is below.

    contactItem = folderItems.Find( $"[FirstName]='{request.FirstName}' and [LastName]='{request.LastName}'" );
    if( contactItem != null )
    {
    	contactItem.SaveAs( "C:\\Users\\username\\Desktop\\" + request.FirstName + request.LastName + ".vcf" );
    }

    Monday, January 23, 2017 6:56 PM
  • If you do not specify the format (second optional parameter), Outlook assumes MSG format. You must explicitly specify the vCard format. Outlook does not look at the extension of the file name to figure out what it is exactly that you want.

    {
    	contactItem.SaveAs( "C:\\Users\\username\\Desktop\\" + request.FirstName + request.LastName + ".vcf", OlSaveAsType.olVCard);
    }


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Monday, January 23, 2017 9:59 PM
  • Thank you very much. I simply didn't know which object to specify (intellisense brings up more options than I cared to look through). This works as expected.
    Monday, January 23, 2017 10:05 PM
  • You might also want to remove invalid characters (such as ":", "\", etc.) when building the file name.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, January 23, 2017 10:06 PM