How to sync my pst file in laptop to Outlook in PC programatically?

S

Simon

Hi all.
I have a problem about sync. I want to sync my laptop and PC
programmatically.
Actually I know there is Import/Export Function in Outlook ,but I want my
program
to do it.
The AddStore method of NameSpace is just putting the pst file to outlook
as a
folder.How can I combine the 2 pst files?? (At least, keep the Inbox folder
up to date).
 
S

Simon

Hi Mc, thank u for ur advice.
but I wanna do the same as the tool kits do. I want to
take control in my code.
 
M

Michael Bauer

Am Wed, 26 Oct 2005 14:37:53 +0800 schrieb Simon:

All in all that´s no easy job!

For the Inbox you could use a simple UserProperty for each MailItem and
store in it whether the item is copied already or not. After the first
synchronizing, all items in both Inboxes should have this flag. The next
time you can then use the Restrict function to find all not copied items.
From one computer open the other *pst with AddStore and copy all the items
returned by Restrict. (AddStore is possible only if the *pst isn´t opened
already.)

So the first keywords (and samples) you could read about in the VBA help
file are:
- For (e.g. For Each to loop through a collection of items)
- AddStore
- Restrict
- Add (i.e. UserProperties.Add)

But that mechanism ignores changes in mails (or in contacts). If you´re
editing received mails (e.g. adding comments) then you´d need a more
complicated mechanism. For comparing those items usually a rule like "last
one wins" is used. That is you need to determine, which item is the last
updated one. Because the system times on both your computers are different
for sure there´s no easy way. I hardly believe a beginner really wants to go
through all this stuff (and spend not hours, but weeks).
 
S

Simon

Thanks.I've got it..
And I am a beginner at Outlook programming only.
It is quite hard to define the rules of update. I am wondering
how the other applications (such as some Mobile Synchronization Tools) do.
It takes me 1 weeks in doing such thing.. I've tried the AddStore methord,
it is complicated to remove it from the Outlook Folder List after AddStore.
So I find out another way. I create a outlook profile temporarily,whose data
restores in my PST file. Then Logon both profiles, and communicates between
them.. I have had written the code, it is just my thought.

Simon
 
M

Michael Bauer

Am Thu, 27 Oct 2005 18:38:14 +0800 schrieb Simon:

For removing a store please use the RemoveStore method.
 
S

Simon

the AddStore method has only 1 parameter that identifies the PST file path,
and how can
I find out the folder that added to the profile ?

void RemoveStore(LPDISPATCH Folder);

Should I enumerate all the folders?? And what identifies the folder I added
just now??

Simon.
 
M

Michael Bauer

Am Fri, 28 Oct 2005 16:10:33 +0800 schrieb Simon:

You can loop through all top folders before adding another one and note
their StoreIDs. Compare that list after AddStore, the missing ID is the new
store´s one.
 
S

Simon

Many thanks.
And I have one question out of the topic: Why there are so many codes in
VB,but few in VC??


Simon
 
M

Michael Bauer

Am Fri, 28 Oct 2005 16:55:41 +0800 schrieb Simon:

Maybe because there´re a lot more VB coders?
 
D

Dan Mitchell

Simon said:
And I have one question out of the topic: Why there are so many codes in
VB,but few in VC??

Two things:

1. If you're writing macros or other things that run inside Outlook,
it'll be written in VBA because that's what VBA's macros use.

2. It's easy enough to translate VB code to C++ code, you can use all the
same methods and such, just replace object.method with object->method and
a bit of tweaking things in and out of variant type. See
http://www.danielmitchell.net/mailfaq, Q5.1.

-- dan
 
G

Guest

Simon,
I'm trying to write a program that will take a users mailbox and write it to
a PST file. Also take an existing PST file and import it into a users
mailbox. Would you let me look at your code so I have a place to start.
(e-mail address removed)
 
S

Simon

1. I know.
2. the methods are the same. but there are still many differences
about the objects. such as :
Dim obj as object
set obj = createobject("xxxx.xxxx");

it takes me quite a lot of time to translate it to VC. maybe just
becoz I am a newbie of OLE/COM programming. hehe.
 
S

Simon

Brian,
I am sorry that I can not send your my code, for the commercial reason,
just like the
others do.
I still don't know how to export the email to a PST file programmatically.
but I can give your
some advice on importing PST file into a user's mailbox.
1. use the method AddStore of the Namespace MAPI to import a PST file as a
folder
in the mailbox and remember its StoreID.
2. if you want to do some sync work, just compare the mails in InBox and
your personal folder
that the PST file is transfered to. And I am still looking 4 a
reasonable condition to judge by.
3. walk through the tree of your mailbox folder, find out the StoreID of
your newly created folder,
and Call RemoveStore to remove it.
That's all.

a fews days ago, I tried another way to import the mails in PST file to the
mailbox. I tried to logon
2 profiles of OL,and sync their mails. But I failed.

Simon
 
S

Simon

Hi Michael,

Does the Restrict function affect the subfolders of the specified
items of a folder? Or must
I work through the whole folder tree recursively ?
 
M

Michael Bauer

Am Mon, 31 Oct 2005 15:12:36 +0800 schrieb Simon:

Restrict affects only the Items collection for which you´re calling the it.
 
M

Michael Bauer

Am Tue, 1 Nov 2005 10:29:04 +0800 schrieb Simon:

Yes. You need to call Restrict for each folder you want to search in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top