|
|
|
date: Fri, 24 Feb 2006 03:00:26 -0800,
group: microsoft.public.exchange2000.development
back
Re: copying contacts from one folder to another
CDO 1.2 and MAPI are not supported in .NET see
http://support.microsoft.com/?kbid=813349 (it usually does work however)
In CDO there is no contact object (you can download the help file from
http://www.cdolive.com/download/cdo.zip) so just treat it as a message and
it should be okay. Eg to copy all the contacts from the default contacts
folder to some other folder in a mailbox
Dim servername As String = "servername"
Dim mailbox As String = "mailbox"
Dim targetfldid As String = "00000000..."
Dim objSession As MAPI.Session = New MAPI.Session
Dim strprofile As String = servername & vbLf & mailbox
objSession.Logon("", , , False, , True, strprofile)
Dim folder1 As MAPI.Folder = objSession.GetDefaultFolder(5)
Dim folder2 As MAPI.Folder = objSession.GetFolder(targetfldid)
For Each objcontact As MAPI.Message In folder1.Messages
Dim objCopyContact As MAPI.Message =
objcontact.CopyTo(folder2.ID)
objCopyContact.Unread = False
objCopyContact.Update()
objCopyContact = Nothing
Console.WriteLine(objcontact.Subject)
Next
objsession.Logoff()
Cheers
Glen
"Col" wrote in message
news:88563840-FB07-4AA7-8F72-89636E110E4D@microsoft.com...
> Hi
>
> I am new to exchange development.
> I am using VS2005
>
> I would like a program to simply copy contacts from one folder to another.
> So far I can define the folders required but am unable to iterate through
> the contacts. I think using "For Each objcontact In
> objpubContactsfolder1.Messages" is the problem as they are contacts not
> messages, but I can't find contacts in intellisense.
>
> Sample Code
>
> ' connect
> Dim servername As String = "serevr.local"
> Dim mailbox As String = "mailbox"
> Dim objSession As New MAPI.Session '= CreateObject("MAPI.Session")
> Dim strProfile = servername & vbLf & mailbox
> objSession.Logon("Outlook", , , False, , True, strProfile)
>
> 'get my mail folder
> Dim objpubstore = objSession.InfoStores("Mailbox - Colin McGrath")
> MsgBox(objpubstore.id)
>
> ' get sub folder. The FolderPath is "\\Mailbox - Colin
> McGrath\Projects\temp\Test1"
> Dim pubContactsfolderid1 As String =
> "0000000010122552B0EB134BA8559308860388D70100A9AD54AD4FE5384ABF1CE002F2DCA23A0000C5C8002A0000"
> Dim objpubContactsfolder1 As MAPI.Folder =
> objSession.GetFolder(pubContactsfolderid1, objpubstore.id)
> MsgBox(objpubContactsfolder1.Name)
>
> Dim objcontact
> For Each objcontact In objpubContactsfolder1.Messages
> MsgBox(objcontact.ID)
> MsgBox(objcontact.FullName)
> Next
>
> objSession.Logoff()
>
>
> Thanks in advance
>
> Colin
date: Mon, 27 Feb 2006 11:21:45 +1100
author: Glen Scales [MVP]
Re: copying contacts from one folder to another
Thanks Glen
Works great, Just what I wanted.
One last thing. My code only works from my development PC only when I am
running Outlook. I did not really want to have outlook open to use this code
as it needs to run on the server. Am I using the wrong technology in CDO ?
should I be using something different ? Or would it be different when I move
it to the exchange server.
Thanks in advance
Col
"Glen Scales [MVP]" wrote:
> CDO 1.2 and MAPI are not supported in .NET see
> http://support.microsoft.com/?kbid=813349 (it usually does work however)
>
> In CDO there is no contact object (you can download the help file from
> http://www.cdolive.com/download/cdo.zip) so just treat it as a message and
> it should be okay. Eg to copy all the contacts from the default contacts
> folder to some other folder in a mailbox
>
> Dim servername As String = "servername"
> Dim mailbox As String = "mailbox"
> Dim targetfldid As String = "00000000..."
> Dim objSession As MAPI.Session = New MAPI.Session
> Dim strprofile As String = servername & vbLf & mailbox
> objSession.Logon("", , , False, , True, strprofile)
> Dim folder1 As MAPI.Folder = objSession.GetDefaultFolder(5)
> Dim folder2 As MAPI.Folder = objSession.GetFolder(targetfldid)
> For Each objcontact As MAPI.Message In folder1.Messages
> Dim objCopyContact As MAPI.Message =
> objcontact.CopyTo(folder2.ID)
> objCopyContact.Unread = False
> objCopyContact.Update()
> objCopyContact = Nothing
> Console.WriteLine(objcontact.Subject)
> Next
> objsession.Logoff()
>
> Cheers
> Glen
>
>
>
> "Col" wrote in message
> news:88563840-FB07-4AA7-8F72-89636E110E4D@microsoft.com...
> > Hi
> >
> > I am new to exchange development.
> > I am using VS2005
> >
> > I would like a program to simply copy contacts from one folder to another.
> > So far I can define the folders required but am unable to iterate through
> > the contacts. I think using "For Each objcontact In
> > objpubContactsfolder1.Messages" is the problem as they are contacts not
> > messages, but I can't find contacts in intellisense.
> >
> > Sample Code
> >
> > ' connect
> > Dim servername As String = "serevr.local"
> > Dim mailbox As String = "mailbox"
> > Dim objSession As New MAPI.Session '= CreateObject("MAPI.Session")
> > Dim strProfile = servername & vbLf & mailbox
> > objSession.Logon("Outlook", , , False, , True, strProfile)
> >
> > 'get my mail folder
> > Dim objpubstore = objSession.InfoStores("Mailbox - Colin McGrath")
> > MsgBox(objpubstore.id)
> >
> > ' get sub folder. The FolderPath is "\\Mailbox - Colin
> > McGrath\Projects\temp\Test1"
> > Dim pubContactsfolderid1 As String =
> > "0000000010122552B0EB134BA8559308860388D70100A9AD54AD4FE5384ABF1CE002F2DCA23A0000C5C8002A0000"
> > Dim objpubContactsfolder1 As MAPI.Folder =
> > objSession.GetFolder(pubContactsfolderid1, objpubstore.id)
> > MsgBox(objpubContactsfolder1.Name)
> >
> > Dim objcontact
> > For Each objcontact In objpubContactsfolder1.Messages
> > MsgBox(objcontact.ID)
> > MsgBox(objcontact.FullName)
> > Next
> >
> > objSession.Logoff()
> >
> >
> > Thanks in advance
> >
> > Colin
>
>
>
date: Tue, 28 Feb 2006 00:49:52 -0800
author: Col
Re: copying contacts from one folder to another
CDO 1.2 doesn't require that you have outlook logged on depending on how you
are using the logon method (and what rights the process that is running the
code has) I would recommend you use temporary profiles instead of specifying
a profile to logon on to eg Session.Logon "",,, False,, True, strProfile.
There a good book on using CDO which you can view the first chapter of which
discus's this in detail http://www.cdolive.com/procdo.htm
If you going to run the code on a server you may find that the CDO 1.2
libraries aren't available on the server you should have a read of
http://www.microsoft.com/technet/prodtechnol/exchange/2003/insider/providers.mspx
and http://support.microsoft.com/?kbid=171440
Cheers
Glen
"Col" wrote in message
news:42966CF0-42A4-4FE4-86DE-31301ECBD193@microsoft.com...
> Thanks Glen
>
> Works great, Just what I wanted.
>
> One last thing. My code only works from my development PC only when I am
> running Outlook. I did not really want to have outlook open to use this
> code
> as it needs to run on the server. Am I using the wrong technology in CDO ?
> should I be using something different ? Or would it be different when I
> move
> it to the exchange server.
>
> Thanks in advance
>
> Col
>
> "Glen Scales [MVP]" wrote:
>
>> CDO 1.2 and MAPI are not supported in .NET see
>> http://support.microsoft.com/?kbid=813349 (it usually does work however)
>>
>> In CDO there is no contact object (you can download the help file from
>> http://www.cdolive.com/download/cdo.zip) so just treat it as a message
>> and
>> it should be okay. Eg to copy all the contacts from the default contacts
>> folder to some other folder in a mailbox
>>
>> Dim servername As String = "servername"
>> Dim mailbox As String = "mailbox"
>> Dim targetfldid As String = "00000000..."
>> Dim objSession As MAPI.Session = New MAPI.Session
>> Dim strprofile As String = servername & vbLf & mailbox
>> objSession.Logon("", , , False, , True, strprofile)
>> Dim folder1 As MAPI.Folder = objSession.GetDefaultFolder(5)
>> Dim folder2 As MAPI.Folder = objSession.GetFolder(targetfldid)
>> For Each objcontact As MAPI.Message In folder1.Messages
>> Dim objCopyContact As MAPI.Message =
>> objcontact.CopyTo(folder2.ID)
>> objCopyContact.Unread = False
>> objCopyContact.Update()
>> objCopyContact = Nothing
>> Console.WriteLine(objcontact.Subject)
>> Next
>> objsession.Logoff()
>>
>> Cheers
>> Glen
>>
>>
>>
>> "Col" wrote in message
>> news:88563840-FB07-4AA7-8F72-89636E110E4D@microsoft.com...
>> > Hi
>> >
>> > I am new to exchange development.
>> > I am using VS2005
>> >
>> > I would like a program to simply copy contacts from one folder to
>> > another.
>> > So far I can define the folders required but am unable to iterate
>> > through
>> > the contacts. I think using "For Each objcontact In
>> > objpubContactsfolder1.Messages" is the problem as they are contacts not
>> > messages, but I can't find contacts in intellisense.
>> >
>> > Sample Code
>> >
>> > ' connect
>> > Dim servername As String = "serevr.local"
>> > Dim mailbox As String = "mailbox"
>> > Dim objSession As New MAPI.Session '=
>> > CreateObject("MAPI.Session")
>> > Dim strProfile = servername & vbLf & mailbox
>> > objSession.Logon("Outlook", , , False, , True, strProfile)
>> >
>> > 'get my mail folder
>> > Dim objpubstore = objSession.InfoStores("Mailbox - Colin
>> > McGrath")
>> > MsgBox(objpubstore.id)
>> >
>> > ' get sub folder. The FolderPath is "\\Mailbox - Colin
>> > McGrath\Projects\temp\Test1"
>> > Dim pubContactsfolderid1 As String =
>> > "0000000010122552B0EB134BA8559308860388D70100A9AD54AD4FE5384ABF1CE002F2DCA23A0000C5C8002A0000"
>> > Dim objpubContactsfolder1 As MAPI.Folder =
>> > objSession.GetFolder(pubContactsfolderid1, objpubstore.id)
>> > MsgBox(objpubContactsfolder1.Name)
>> >
>> > Dim objcontact
>> > For Each objcontact In objpubContactsfolder1.Messages
>> > MsgBox(objcontact.ID)
>> > MsgBox(objcontact.FullName)
>> > Next
>> >
>> > objSession.Logoff()
>> >
>> >
>> > Thanks in advance
>> >
>> > Colin
>>
>>
>>
date: Wed, 1 Mar 2006 11:04:55 +1100
author: Glen Scales [MVP]
Re: copying contacts from one folder to another
Hi Glen
That's great. However I have (hopefully) one last question. The original
code you posted works fine on folders in my mailbox until I try to use it on
a public folder. It then fails with the error "E_FAIL(80004005)" on the
first iteration of the foreach loop.
I am sure it must be an access problem, but not sure what. I have "owner"
permissions to these public folders. What more do I need?
Thanks in advance
Col
"Glen Scales [MVP]" wrote:
> CDO 1.2 doesn't require that you have outlook logged on depending on how you
> are using the logon method (and what rights the process that is running the
> code has) I would recommend you use temporary profiles instead of specifying
> a profile to logon on to eg Session.Logon "",,, False,, True, strProfile.
> There a good book on using CDO which you can view the first chapter of which
> discus's this in detail http://www.cdolive.com/procdo.htm
>
> If you going to run the code on a server you may find that the CDO 1.2
> libraries aren't available on the server you should have a read of
> http://www.microsoft.com/technet/prodtechnol/exchange/2003/insider/providers.mspx
> and http://support.microsoft.com/?kbid=171440
>
> Cheers
> Glen
>
>
> "Col" wrote in message
> news:42966CF0-42A4-4FE4-86DE-31301ECBD193@microsoft.com...
> > Thanks Glen
> >
> > Works great, Just what I wanted.
> >
> > One last thing. My code only works from my development PC only when I am
> > running Outlook. I did not really want to have outlook open to use this
> > code
> > as it needs to run on the server. Am I using the wrong technology in CDO ?
> > should I be using something different ? Or would it be different when I
> > move
> > it to the exchange server.
> >
> > Thanks in advance
> >
> > Col
> >
> > "Glen Scales [MVP]" wrote:
> >
> >> CDO 1.2 and MAPI are not supported in .NET see
> >> http://support.microsoft.com/?kbid=813349 (it usually does work however)
> >>
> >> In CDO there is no contact object (you can download the help file from
> >> http://www.cdolive.com/download/cdo.zip) so just treat it as a message
> >> and
> >> it should be okay. Eg to copy all the contacts from the default contacts
> >> folder to some other folder in a mailbox
> >>
> >> Dim servername As String = "servername"
> >> Dim mailbox As String = "mailbox"
> >> Dim targetfldid As String = "00000000..."
> >> Dim objSession As MAPI.Session = New MAPI.Session
> >> Dim strprofile As String = servername & vbLf & mailbox
> >> objSession.Logon("", , , False, , True, strprofile)
> >> Dim folder1 As MAPI.Folder = objSession.GetDefaultFolder(5)
> >> Dim folder2 As MAPI.Folder = objSession.GetFolder(targetfldid)
> >> For Each objcontact As MAPI.Message In folder1.Messages
> >> Dim objCopyContact As MAPI.Message =
> >> objcontact.CopyTo(folder2.ID)
> >> objCopyContact.Unread = False
> >> objCopyContact.Update()
> >> objCopyContact = Nothing
> >> Console.WriteLine(objcontact.Subject)
> >> Next
> >> objsession.Logoff()
> >>
> >> Cheers
> >> Glen
> >>
> >>
> >>
> >> "Col" wrote in message
> >> news:88563840-FB07-4AA7-8F72-89636E110E4D@microsoft.com...
> >> > Hi
> >> >
> >> > I am new to exchange development.
> >> > I am using VS2005
> >> >
> >> > I would like a program to simply copy contacts from one folder to
> >> > another.
> >> > So far I can define the folders required but am unable to iterate
> >> > through
> >> > the contacts. I think using "For Each objcontact In
> >> > objpubContactsfolder1.Messages" is the problem as they are contacts not
> >> > messages, but I can't find contacts in intellisense.
> >> >
> >> > Sample Code
> >> >
> >> > ' connect
> >> > Dim servername As String = "serevr.local"
> >> > Dim mailbox As String = "mailbox"
> >> > Dim objSession As New MAPI.Session '=
> >> > CreateObject("MAPI.Session")
> >> > Dim strProfile = servername & vbLf & mailbox
> >> > objSession.Logon("Outlook", , , False, , True, strProfile)
> >> >
> >> > 'get my mail folder
> >> > Dim objpubstore = objSession.InfoStores("Mailbox - Colin
> >> > McGrath")
> >> > MsgBox(objpubstore.id)
> >> >
> >> > ' get sub folder. The FolderPath is "\\Mailbox - Colin
> >> > McGrath\Projects\temp\Test1"
> >> > Dim pubContactsfolderid1 As String =
> >> > "0000000010122552B0EB134BA8559308860388D70100A9AD54AD4FE5384ABF1CE002F2DCA23A0000C5C8002A0000"
> >> > Dim objpubContactsfolder1 As MAPI.Folder =
> >> > objSession.GetFolder(pubContactsfolderid1, objpubstore.id)
> >> > MsgBox(objpubContactsfolder1.Name)
> >> >
> >> > Dim objcontact
> >> > For Each objcontact In objpubContactsfolder1.Messages
> >> > MsgBox(objcontact.ID)
> >> > MsgBox(objcontact.FullName)
> >> > Next
> >> >
> >> > objSession.Logoff()
> >> >
> >> >
> >> > Thanks in advance
> >> >
> >> > Colin
> >>
> >>
> >>
>
>
>
date: Fri, 3 Mar 2006 07:03:28 -0800
author: Col
Re: copying contacts from one folder to another
When you say public folder are you copying from one public folder to the
other or a public folder to a mailbox. You may need to include the public
folder store ID in this case.
Cheers
Glen
"Col" wrote in message
news:666E9E20-8CDF-467C-BBB4-D01E0F4A99F9@microsoft.com...
> Hi Glen
>
> That's great. However I have (hopefully) one last question. The original
> code you posted works fine on folders in my mailbox until I try to use it
> on
> a public folder. It then fails with the error "E_FAIL(80004005)" on the
> first iteration of the foreach loop.
> I am sure it must be an access problem, but not sure what. I have "owner"
> permissions to these public folders. What more do I need?
>
> Thanks in advance
>
> Col
>
> "Glen Scales [MVP]" wrote:
>
>> CDO 1.2 doesn't require that you have outlook logged on depending on how
>> you
>> are using the logon method (and what rights the process that is running
>> the
>> code has) I would recommend you use temporary profiles instead of
>> specifying
>> a profile to logon on to eg Session.Logon "",,, False,, True, strProfile.
>> There a good book on using CDO which you can view the first chapter of
>> which
>> discus's this in detail http://www.cdolive.com/procdo.htm
>>
>> If you going to run the code on a server you may find that the CDO 1.2
>> libraries aren't available on the server you should have a read of
>> http://www.microsoft.com/technet/prodtechnol/exchange/2003/insider/providers.mspx
>> and http://support.microsoft.com/?kbid=171440
>>
>> Cheers
>> Glen
>>
>>
>> "Col" wrote in message
>> news:42966CF0-42A4-4FE4-86DE-31301ECBD193@microsoft.com...
>> > Thanks Glen
>> >
>> > Works great, Just what I wanted.
>> >
>> > One last thing. My code only works from my development PC only when I
>> > am
>> > running Outlook. I did not really want to have outlook open to use this
>> > code
>> > as it needs to run on the server. Am I using the wrong technology in
>> > CDO ?
>> > should I be using something different ? Or would it be different when I
>> > move
>> > it to the exchange server.
>> >
>> > Thanks in advance
>> >
>> > Col
>> >
>> > "Glen Scales [MVP]" wrote:
>> >
>> >> CDO 1.2 and MAPI are not supported in .NET see
>> >> http://support.microsoft.com/?kbid=813349 (it usually does work
>> >> however)
>> >>
>> >> In CDO there is no contact object (you can download the help file from
>> >> http://www.cdolive.com/download/cdo.zip) so just treat it as a message
>> >> and
>> >> it should be okay. Eg to copy all the contacts from the default
>> >> contacts
>> >> folder to some other folder in a mailbox
>> >>
>> >> Dim servername As String = "servername"
>> >> Dim mailbox As String = "mailbox"
>> >> Dim targetfldid As String = "00000000..."
>> >> Dim objSession As MAPI.Session = New MAPI.Session
>> >> Dim strprofile As String = servername & vbLf & mailbox
>> >> objSession.Logon("", , , False, , True, strprofile)
>> >> Dim folder1 As MAPI.Folder = objSession.GetDefaultFolder(5)
>> >> Dim folder2 As MAPI.Folder = objSession.GetFolder(targetfldid)
>> >> For Each objcontact As MAPI.Message In folder1.Messages
>> >> Dim objCopyContact As MAPI.Message =
>> >> objcontact.CopyTo(folder2.ID)
>> >> objCopyContact.Unread = False
>> >> objCopyContact.Update()
>> >> objCopyContact = Nothing
>> >> Console.WriteLine(objcontact.Subject)
>> >> Next
>> >> objsession.Logoff()
>> >>
>> >> Cheers
>> >> Glen
>> >>
>> >>
>> >>
>> >> "Col" wrote in message
>> >> news:88563840-FB07-4AA7-8F72-89636E110E4D@microsoft.com...
>> >> > Hi
>> >> >
>> >> > I am new to exchange development.
>> >> > I am using VS2005
>> >> >
>> >> > I would like a program to simply copy contacts from one folder to
>> >> > another.
>> >> > So far I can define the folders required but am unable to iterate
>> >> > through
>> >> > the contacts. I think using "For Each objcontact In
>> >> > objpubContactsfolder1.Messages" is the problem as they are contacts
>> >> > not
>> >> > messages, but I can't find contacts in intellisense.
>> >> >
>> >> > Sample Code
>> >> >
>> >> > ' connect
>> >> > Dim servername As String = "serevr.local"
>> >> > Dim mailbox As String = "mailbox"
>> >> > Dim objSession As New MAPI.Session '=
>> >> > CreateObject("MAPI.Session")
>> >> > Dim strProfile = servername & vbLf & mailbox
>> >> > objSession.Logon("Outlook", , , False, , True, strProfile)
>> >> >
>> >> > 'get my mail folder
>> >> > Dim objpubstore = objSession.InfoStores("Mailbox - Colin
>> >> > McGrath")
>> >> > MsgBox(objpubstore.id)
>> >> >
>> >> > ' get sub folder. The FolderPath is "\\Mailbox - Colin
>> >> > McGrath\Projects\temp\Test1"
>> >> > Dim pubContactsfolderid1 As String =
>> >> > "0000000010122552B0EB134BA8559308860388D70100A9AD54AD4FE5384ABF1CE002F2DCA23A0000C5C8002A0000"
>> >> > Dim objpubContactsfolder1 As MAPI.Folder =
>> >> > objSession.GetFolder(pubContactsfolderid1, objpubstore.id)
>> >> > MsgBox(objpubContactsfolder1.Name)
>> >> >
>> >> > Dim objcontact
>> >> > For Each objcontact In objpubContactsfolder1.Messages
>> >> > MsgBox(objcontact.ID)
>> >> > MsgBox(objcontact.FullName)
>> >> > Next
>> >> >
>> >> > objSession.Logoff()
>> >> >
>> >> >
>> >> > Thanks in advance
>> >> >
>> >> > Colin
>> >>
>> >>
>> >>
>>
>>
>>
date: Mon, 6 Mar 2006 09:46:24 +1100
author: Glen Scales [MVP]
Re: copying contacts from one folder to another
Hi Glen
Yes, adding the ID sorted it out. Many thanks for your time and effort in
helping me.
It is really apppreciated.
Regards
Colin
"Glen Scales [MVP]" wrote:
> When you say public folder are you copying from one public folder to the
> other or a public folder to a mailbox. You may need to include the public
> folder store ID in this case.
>
> Cheers
> Glen
> "Col" wrote in message
> news:666E9E20-8CDF-467C-BBB4-D01E0F4A99F9@microsoft.com...
> > Hi Glen
> >
> > That's great. However I have (hopefully) one last question. The original
> > code you posted works fine on folders in my mailbox until I try to use it
> > on
> > a public folder. It then fails with the error "E_FAIL(80004005)" on the
> > first iteration of the foreach loop.
> > I am sure it must be an access problem, but not sure what. I have "owner"
> > permissions to these public folders. What more do I need?
> >
> > Thanks in advance
> >
> > Col
> >
> > "Glen Scales [MVP]" wrote:
> >
> >> CDO 1.2 doesn't require that you have outlook logged on depending on how
> >> you
> >> are using the logon method (and what rights the process that is running
> >> the
> >> code has) I would recommend you use temporary profiles instead of
> >> specifying
> >> a profile to logon on to eg Session.Logon "",,, False,, True, strProfile.
> >> There a good book on using CDO which you can view the first chapter of
> >> which
> >> discus's this in detail http://www.cdolive.com/procdo.htm
> >>
> >> If you going to run the code on a server you may find that the CDO 1.2
> >> libraries aren't available on the server you should have a read of
> >> http://www.microsoft.com/technet/prodtechnol/exchange/2003/insider/providers.mspx
> >> and http://support.microsoft.com/?kbid=171440
> >>
> >> Cheers
> >> Glen
> >>
> >>
> >> "Col" wrote in message
> >> news:42966CF0-42A4-4FE4-86DE-31301ECBD193@microsoft.com...
> >> > Thanks Glen
> >> >
> >> > Works great, Just what I wanted.
> >> >
> >> > One last thing. My code only works from my development PC only when I
> >> > am
> >> > running Outlook. I did not really want to have outlook open to use this
> >> > code
> >> > as it needs to run on the server. Am I using the wrong technology in
> >> > CDO ?
> >> > should I be using something different ? Or would it be different when I
> >> > move
> >> > it to the exchange server.
> >> >
> >> > Thanks in advance
> >> >
> >> > Col
> >> >
> >> > "Glen Scales [MVP]" wrote:
> >> >
> >> >> CDO 1.2 and MAPI are not supported in .NET see
> >> >> http://support.microsoft.com/?kbid=813349 (it usually does work
> >> >> however)
> >> >>
> >> >> In CDO there is no contact object (you can download the help file from
> >> >> http://www.cdolive.com/download/cdo.zip) so just treat it as a message
> >> >> and
> >> >> it should be okay. Eg to copy all the contacts from the default
> >> >> contacts
> >> >> folder to some other folder in a mailbox
> >> >>
> >> >> Dim servername As String = "servername"
> >> >> Dim mailbox As String = "mailbox"
> >> >> Dim targetfldid As String = "00000000..."
> >> >> Dim objSession As MAPI.Session = New MAPI.Session
> >> >> Dim strprofile As String = servername & vbLf & mailbox
> >> >> objSession.Logon("", , , False, , True, strprofile)
> >> >> Dim folder1 As MAPI.Folder = objSession.GetDefaultFolder(5)
> >> >> Dim folder2 As MAPI.Folder = objSession.GetFolder(targetfldid)
> >> >> For Each objcontact As MAPI.Message In folder1.Messages
> >> >> Dim objCopyContact As MAPI.Message =
> >> >> objcontact.CopyTo(folder2.ID)
> >> >> objCopyContact.Unread = False
> >> >> objCopyContact.Update()
> >> >> objCopyContact = Nothing
> >> >> Console.WriteLine(objcontact.Subject)
> >> >> Next
> >> >> objsession.Logoff()
> >> >>
> >> >> Cheers
> >> >> Glen
> >> >>
> >> >>
> >> >>
> >> >> "Col" wrote in message
> >> >> news:88563840-FB07-4AA7-8F72-89636E110E4D@microsoft.com...
> >> >> > Hi
> >> >> >
> >> >> > I am new to exchange development.
> >> >> > I am using VS2005
> >> >> >
> >> >> > I would like a program to simply copy contacts from one folder to
> >> >> > another.
> >> >> > So far I can define the folders required but am unable to iterate
> >> >> > through
> >> >> > the contacts. I think using "For Each objcontact In
> >> >> > objpubContactsfolder1.Messages" is the problem as they are contacts
> >> >> > not
> >> >> > messages, but I can't find contacts in intellisense.
> >> >> >
> >> >> > Sample Code
> >> >> >
> >> >> > ' connect
> >> >> > Dim servername As String = "serevr.local"
> >> >> > Dim mailbox As String = "mailbox"
> >> >> > Dim objSession As New MAPI.Session '=
> >> >> > CreateObject("MAPI.Session")
> >> >> > Dim strProfile = servername & vbLf & mailbox
> >> >> > objSession.Logon("Outlook", , , False, , True, strProfile)
> >> >> >
> >> >> > 'get my mail folder
> >> >> > Dim objpubstore = objSession.InfoStores("Mailbox - Colin
> >> >> > McGrath")
> >> >> > MsgBox(objpubstore.id)
> >> >> >
> >> >> > ' get sub folder. The FolderPath is "\\Mailbox - Colin
> >> >> > McGrath\Projects\temp\Test1"
> >> >> > Dim pubContactsfolderid1 As String =
> >> >> > "0000000010122552B0EB134BA8559308860388D70100A9AD54AD4FE5384ABF1CE002F2DCA23A0000C5C8002A0000"
> >> >> > Dim objpubContactsfolder1 As MAPI.Folder =
> >> >> > objSession.GetFolder(pubContactsfolderid1, objpubstore.id)
> >> >> > MsgBox(objpubContactsfolder1.Name)
> >> >> >
> >> >> > Dim objcontact
> >> >> > For Each objcontact In objpubContactsfolder1.Messages
> >> >> > MsgBox(objcontact.ID)
> >> >> > MsgBox(objcontact.FullName)
> >> >> > Next
> >> >> >
> >> >> > objSession.Logoff()
> >> >> >
> >> >> >
> >> >> > Thanks in advance
> >> >> >
> >> >> > Colin
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
date: Mon, 6 Mar 2006 06:17:27 -0800
author: Col
|
|