none
Import and Export Outlook Contacts To SQL db Via asp.net web application RRS feed

  • Question

  • Hi all

     

    I serach for any thing help on this issue but I get Nothing anyone can help me Plesae

     

     

    thanks & regards

     

    Wednesday, July 18, 2007 9:14 AM

All replies

  • This will work on Office 2003
    You will just have to "Add Reference" to "Microsoft Outlook 11.0 Object Library" (or any other version depending on the version of Office on your machine)

    It is not working on Office 2007! (12 Object Library)


     //Create Outlook Application
            MyOutlook.Application oApp = new MyOutlook.Application();
            oApp.AnswerWizard.ClearFileList();
            oApp.ActiveWindow();

            MyOutlook.MAPIFolder oContacts = (MyOutlook.MAPIFolder)oApp.Application.ActiveExplorer().Session.GetDefaultFolder(MyOutlook.OlDefaultFolders.olFolderContacts);


            foreach (MyOutlook.ContactItem oContact in oContacts.Items)
            {

                Response.Write(oContact.Email1DisplayName);
            }

    Wednesday, July 18, 2007 4:39 PM
  • Hi

     

    i using your code as you type but Converted to VB.net as below

     

    Dim oApp As New MyOutlook.Application

    oApp.AnswerWizard.ClearFileList()

    oApp.ActiveWindow()

    Dim oContacts As MyOutlook.MAPIFolder = DirectCast(oApp.Application.ActiveExplorer().Session.GetDefaultFolder(MyOutlook.OlDefaultFolders.olFolderContacts), MyOutlook.MAPIFolder)

     

    For Each oContact As MyOutlook.ContactItem In oContacts.Items

    Response.Write(oContact.Email1DisplayName)

    Next

     

    I trace the code but get looping

     

    did U have any suggest

     

    thanks

    Thursday, July 19, 2007 9:48 AM
  • check

    oContacts.Items.Count

    does it contain the number of contacts in your outlook?

     

     

    Thursday, July 19, 2007 11:32 AM
  •  

    I get this error after execution

     

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 36:         oApp.ActiveWindow()
    Line 37: 
    Line 38:         Dim oContacts As MyOutlook.MAPIFolder = DirectCast(oApp.Application.ActiveExplorer().Session.GetDefaultFolder(MyOutlook.OlDefaultFolders.olFolderContacts), MyOutlook.MAPIFolder)
    Line 39: 
    Line 40: 

    Thursday, July 19, 2007 12:25 PM
  • Did you add reference to "Microsoft Outlook 11.0 Object Library"?

    and are using Office 2003?

     

    Best Regards

    Thursday, July 19, 2007 3:01 PM
  • I iused the 2 Ways

    -- Using "Microsoft Outlook 12.0 Object Library", office 2007

     Error I get

                 Opertion Faild

     

     

    Using "Microsoft Outlook 11.0 Object Library", office 2003

           error i get

     

    Cast not valid but go and read all contact error apear when start Write

     

    response.warite(oContact.firstname)

     

    thanks

    Sunday, July 22, 2007 1:03 PM
  • I believe that the suggested solution may not work for the client as the code would be executing on the server therefore it will only ever work on the server. You need some form of clientside coding to do this but this may also involve alot of security issues, such as the user disabling scripting on their browser or perhaps require some runtime files installed on their system in order to interact with the operation.
    Sunday, July 22, 2007 7:36 PM
  • when start looping in the contact item and write values to db i get this error , but i read only the first one

     

    Specified cast is not valid.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Specified cast is not valid.

    Source Error:

    Line 47: 
    Line 48:         'Try
    Line 49:         For Each oContact As MyOutlook.ContactItem In oContacts.Items
    Line 50:             Dim FN As String = oContact.Email1DisplayName
    Line 51:             Response.Write(FN)
    Tuesday, July 24, 2007 9:40 AM
  • finally it worked!!

    did you use Office 2003?

     

    try to remove the groups... only keep the contacts and try again!

     

    Tuesday, July 24, 2007 9:59 PM
  • yes..this code will only access your outlook..or outllooks in the same domain

    If you want to make it access the client PCs then you better make it win app/service.

    Tuesday, July 24, 2007 10:07 PM
  • yeah , finally

    your suggest  is good kindly can you tell how can i strat to import contacts from pc(s)

    Wednesday, July 25, 2007 10:31 AM
  • is it a web applictaion?

    will it be used in a LAN? or over the net?

     

    Wednesday, July 25, 2007 10:40 AM
  • yaeh web app. and it will be over lan
    Wednesday, July 25, 2007 10:44 AM
  • I faceing Strange  problem , after i can import from outlook and i tested many times last time when import .
    i get error
     
    Access is denied
     

    i  remove the reference and add again , when i build i get

    Namespace or type 'Outlook' for the Imports 'Microsoft.Office.Interop.Outlook' cannot be found.
     
    and all Syntax on this Namespace
     
    Sad

     
    any sugeest ,
    Wednesday, July 25, 2007 2:36 PM
  • I guess some settings have changed … in case you didn't change anything in your machine then try to repair the office

     

    There are some considerations to be able to get the contacts from different Outlooks over the LAN:

    1. This code will only work with Office 2003 as you see! So you have to be sure that all the clients are using 2003
    2. You have to filter the contacts to avoid duplicates.

     

    You can make a windows application to be downloaded and run from each client PC

     

    Best Regards

     

    Wednesday, July 25, 2007 5:33 PM
  • I repair but the error as is but working when  reinstall office but i don't figuer out the problem .

    after Installation i have the following error

     

     

    Access is denied  

    in line . "Dim Outlobj As New MyOutlook.Application"

     

    thanks & Regards

     

     

     

     

     

     

    Thursday, July 26, 2007 9:41 AM