MailItem Move

N

Neetu

Hello,

We are working on folders creation addin for outlook 2007 using VSTO.
We are creation set of folders inside add-in.
We have requirement -> not to allow user to drag any mailitem inside our
custom folder before login.
we have created a folderwrapper class and attaction events for all our folder
Add Item evnent

public virtual void Item_Add(object vobjItem)
{
MailItem lobjMailItem = null;
try
{
if (ClientInfo.Instance.LoginStatus == LoggedIn.No)
{
((MailItem)vobjItem).Move(Utility.SelectedFolder);
MessageBox.Show("You are not logged-in.Mail Has been
moved previous folder.Please login ");
return;
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
this code works fine , if we drags a folder from inbuilt folder of
Outlook like draft, inbox etc.
this also works fine , if we are doing ctrl + drag from some user created
folder.
however when we do simple drag from a user created folder .
((MailItem)vobjItem).Move(Utility.SelectedFolder);
code gives error "Mailitem cannot Move".

Utility.SelectedFolder -> a global variable to keep last selected folder to
move back the item back to last choosen folder.
Any help or tips are welcome.
 
D

Dmitry Streblechenko

Why not use the MAPIFolder.BeforeITemMove event which lets you cancel the
operation?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
N

Neetu

I attached BeforeITemMove event to my folder class
however this event is fired when I am dragging Mail item out of our custom
folder.
I need to captured event when a mailitem dragged into our custom folder.
 
N

Neetu

how can we trap if any new folder has been dragged into our custom folder in
outlook 2007 using c# and VSTO?
 
D

Dmitry Streblechenko

Set up the event handler on the currently selected folder, not your custom
folder: trap Explorer.FolderSwitch event, set up the Folder.BeforeItemMove
for the Explorer.CurrentFolder object.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
N

Neetu

Hello Dmitry

Thanks for reply.

I have 2 more question for MAPI folders

1. Can we make MAPIFolders as disable or unable using c# and VSTO for
outlook 2007 or outlook 2003?
2. How can we keep a trak of event of folder addintion or move or delete
from outlook.

I need to keep a watch on if any folder has been added to outlook , its
parents.
if any change in parent folder ( in case move).

or folder delete from outlook (Moved to delete folders)

which events I need to listen inside outlook ?
 
D

Dmitry Streblechenko

1. Not unless you write your own store provider
2. Folder.FolderAdd and Folders.FolderRemove events. Keep in mind that
evenst are not designed for any kind of synchronization: they can be (and
are) dropped under heavy loads, your code must be listenign to teh events at
all times, etc.
You can use events as a hint that something happened and you need to run
your sync sooner rather than later, but they shoudl not be used as a sole
sync API.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
N

Neetu

Hello Dmitry

For Preventing Item or folder move from or into a Custom folder
I have attached below event for explorer
this.Application.ActiveExplorer().BeforeFolderSwitch += new
ExplorerEvents_10_BeforeFolderSwitchEventHandler(BeforeFolderSwitch);

in BeforeFolderSwitch event attached be these two events.

(vobjMAPIFolder as Folder).BeforeItemMove += new
MAPIFolderEvents_12_BeforeItemMoveEventHandler(BeforeItemMove);
(vobjMAPIFolder as Folder).BeforeFolderMove += new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);

Its work fine if we do explicit folder selection and it fires
BeforeFolderSwitch event
and selectedfolder gets attached with events for beforefoldermove and before
item move.

however when we drag a folder with out selecting folder then folder switch
doens't work.
which event of explorer should be use to find selected folder?
I used viewswitch and SelectionChange however its not working for all
condition
 
N

Neetu

At startup , I m attaching 3 events to each all folders inside Outlook

1. BeforeItemMove
2. BeforeFolderMove
3. FolderAdd

Even on BeforeSwitchEvent I am attaching these 3 events to selected folder.
However these events gets fire only if BeforeSwitchEvents gets fire i.e when
we are selecting Folder Explicitly.
if I drag folder without selecting it then beforeFolderMove Does't get fire.
Once folder gets selected and BeforeSwitchEvents gets fire after that , its
all three events gets Fire event if don't select it explicitly.

can't be Attach events to folders at startup with recursive functions?
 
D

Dmitry Streblechenko

You could set up event sinks on each and every folder, but that will hardly
be efficient. And you will run into problems if you have too many folders in
an online Exchnage mode. Plus you would need to handle situatiosn when new
folders are created and old folders are removed.
I would take another look at your app architecture if I were you...

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
N

Neetu

Hello Dmitry

For my below mentioned issue I have another solution not fully working( need
to find the reason)

I have created a Class called OutlookFolderWrapper.

internal class OutlookFolderWrapper
{
private Folder mobjFolder;

public Folder Folder
{
get { return mobjFolder; }
set { mobjFolder = value; }
}

private Folders mobjFolders;
public Folders FoldersCollection
{
get { return mobjFolders; }
}


private static Hashtable mcolFoldercollection = new Hashtable();
public static Hashtable FolderCollection
{
get { return mcolFoldercollection; }
}


private OutlookFolderWrapper(ref MAPIFolder vobjmfFolder)
{
mobjFolders = vobjmfFolder.Folders;
mobjFolder = vobjmfFolder as Folder;
if (vobjmfFolder.Parent != null)
mobjParentFolder = vobjmfFolder.Parent as MAPIFolder;

if (mobjFolders != null)
mobjFolders.FolderAdd += new
FoldersEvents_FolderAddEventHandler(FolderAdd);

(mobjFolder).BeforeFolderMove += new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);
if(mobjParentFolder!=null)
(mobjParentFolder as Folder).BeforeFolderMove+=new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);
}

public static void BeforeFolderMove(MAPIFolder vobjmfMoveTo, ref bool
Cancel)
{
int lint = 0;
if (IsPartOfAddinFolders(vobjmfMoveTo, ref lint)) //function
Find if target folder is our addin folder
{
Cancel = true;
System.Windows.Forms.MessageBox.Show("Folder can not move to
our Addin folder");
}
}

public static void FolderAdd( MAPIFolder vobjNewFolder)
{
IsFolderAlreadyExist(ref vobjNewFolder);
}

public static void IsFolderAlreadyExist(ref MAPIFolder vobjmfFolder)
{
string lstrEntryKey = vobjmfFolder.EntryID;
if (mcolFoldercollection.ContainsKey(lstrEntryKey))
mcolFoldercollection.Remove(lstrEntryKey);

OutlookFolderWrapper lobjOutlookFolder = new
OutlookFolderWrapper(ref vobjmfFolder);

mcolFoldercollection.Add(lstrEntryKey, lobjOutlookFolder);

}
}



At start up of my addin by recursive function , inside this ThisAddin.cs
I m creating a wrapper class object for all existing folders iniside Outlook
and keeping inside a hashtable which is a static member of
outlookFolderWrapper class.

private void AttachEventsForOutlookFolders(ref MAPIFolder vobjmfFolder)
{
int lin = 0;
if (!IsPartOfAddinFolders(vobjmfFolder, ref lint))
{
OutlookFolderWrapper.IsFolderAlreadyExist(ref vobjmfFolder);

}
for (int i = 1; i <= vobjmfFolder.Folders.Count; i++)
{
MAPIFolder lobjFolder = vobjmfFolder.Folders as MAPIFolder;
AttachEventsForOutlookFolders(ref lobjFolder);
}

}

This Wrapper function works well if we creates a folder after startup. Both
FolderAdd and BeforefolderMove event for new folder get fires however on
already exist folder only folderAdd event works means get fires.
beforeFoldermove doens't get fire at all.

Any idea Why out of 2 events only 1 works?
 
D

Dmitry Streblechenko

mobjFolders variable must be alive at all times. You have as a local
vaariables, which means GC will release it whenevre it pleases.
Make it a class member.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Neetu said:
Hello Dmitry

For my below mentioned issue I have another solution not fully working(
need
to find the reason)

I have created a Class called OutlookFolderWrapper.

internal class OutlookFolderWrapper
{
private Folder mobjFolder;

public Folder Folder
{
get { return mobjFolder; }
set { mobjFolder = value; }
}

private Folders mobjFolders;
public Folders FoldersCollection
{
get { return mobjFolders; }
}


private static Hashtable mcolFoldercollection = new Hashtable();
public static Hashtable FolderCollection
{
get { return mcolFoldercollection; }
}


private OutlookFolderWrapper(ref MAPIFolder vobjmfFolder)
{
mobjFolders = vobjmfFolder.Folders;
mobjFolder = vobjmfFolder as Folder;
if (vobjmfFolder.Parent != null)
mobjParentFolder = vobjmfFolder.Parent as MAPIFolder;

if (mobjFolders != null)
mobjFolders.FolderAdd += new
FoldersEvents_FolderAddEventHandler(FolderAdd);

(mobjFolder).BeforeFolderMove += new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);
if(mobjParentFolder!=null)
(mobjParentFolder as Folder).BeforeFolderMove+=new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);
}

public static void BeforeFolderMove(MAPIFolder vobjmfMoveTo, ref bool
Cancel)
{
int lint = 0;
if (IsPartOfAddinFolders(vobjmfMoveTo, ref lint)) //function
Find if target folder is our addin folder
{
Cancel = true;
System.Windows.Forms.MessageBox.Show("Folder can not move
to
our Addin folder");
}
}

public static void FolderAdd( MAPIFolder vobjNewFolder)
{
IsFolderAlreadyExist(ref vobjNewFolder);
}

public static void IsFolderAlreadyExist(ref MAPIFolder
vobjmfFolder)
{
string lstrEntryKey = vobjmfFolder.EntryID;
if (mcolFoldercollection.ContainsKey(lstrEntryKey))
mcolFoldercollection.Remove(lstrEntryKey);

OutlookFolderWrapper lobjOutlookFolder = new
OutlookFolderWrapper(ref vobjmfFolder);

mcolFoldercollection.Add(lstrEntryKey, lobjOutlookFolder);

}
}



At start up of my addin by recursive function , inside this ThisAddin.cs
I m creating a wrapper class object for all existing folders iniside
Outlook
and keeping inside a hashtable which is a static member of
outlookFolderWrapper class.

private void AttachEventsForOutlookFolders(ref MAPIFolder vobjmfFolder)
{
int lin = 0;
if (!IsPartOfAddinFolders(vobjmfFolder, ref lint))
{
OutlookFolderWrapper.IsFolderAlreadyExist(ref
vobjmfFolder);

}
for (int i = 1; i <= vobjmfFolder.Folders.Count; i++)
{
MAPIFolder lobjFolder = vobjmfFolder.Folders as
MAPIFolder;
AttachEventsForOutlookFolders(ref lobjFolder);
}

}

This Wrapper function works well if we creates a folder after startup.
Both
FolderAdd and BeforefolderMove event for new folder get fires however on
already exist folder only folderAdd event works means get fires.
beforeFoldermove doens't get fire at all.

Any idea Why out of 2 events only 1 works?

Dmitry Streblechenko said:
You could set up event sinks on each and every folder, but that will
hardly
be efficient. And you will run into problems if you have too many folders
in
an online Exchnage mode. Plus you would need to handle situatiosn when
new
folders are created and old folders are removed.
I would take another look at your app architecture if I were you...

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
N

Neetu

This folder is defined at class level .its a member variable of class with
access modier as private.


Dmitry Streblechenko said:
mobjFolders variable must be alive at all times. You have as a local
vaariables, which means GC will release it whenevre it pleases.
Make it a class member.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Neetu said:
Hello Dmitry

For my below mentioned issue I have another solution not fully working(
need
to find the reason)

I have created a Class called OutlookFolderWrapper.

internal class OutlookFolderWrapper
{
private Folder mobjFolder;

public Folder Folder
{
get { return mobjFolder; }
set { mobjFolder = value; }
}

private Folders mobjFolders;
public Folders FoldersCollection
{
get { return mobjFolders; }
}


private static Hashtable mcolFoldercollection = new Hashtable();
public static Hashtable FolderCollection
{
get { return mcolFoldercollection; }
}


private OutlookFolderWrapper(ref MAPIFolder vobjmfFolder)
{
mobjFolders = vobjmfFolder.Folders;
mobjFolder = vobjmfFolder as Folder;
if (vobjmfFolder.Parent != null)
mobjParentFolder = vobjmfFolder.Parent as MAPIFolder;

if (mobjFolders != null)
mobjFolders.FolderAdd += new
FoldersEvents_FolderAddEventHandler(FolderAdd);

(mobjFolder).BeforeFolderMove += new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);
if(mobjParentFolder!=null)
(mobjParentFolder as Folder).BeforeFolderMove+=new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);
}

public static void BeforeFolderMove(MAPIFolder vobjmfMoveTo, ref bool
Cancel)
{
int lint = 0;
if (IsPartOfAddinFolders(vobjmfMoveTo, ref lint)) //function
Find if target folder is our addin folder
{
Cancel = true;
System.Windows.Forms.MessageBox.Show("Folder can not move
to
our Addin folder");
}
}

public static void FolderAdd( MAPIFolder vobjNewFolder)
{
IsFolderAlreadyExist(ref vobjNewFolder);
}

public static void IsFolderAlreadyExist(ref MAPIFolder
vobjmfFolder)
{
string lstrEntryKey = vobjmfFolder.EntryID;
if (mcolFoldercollection.ContainsKey(lstrEntryKey))
mcolFoldercollection.Remove(lstrEntryKey);

OutlookFolderWrapper lobjOutlookFolder = new
OutlookFolderWrapper(ref vobjmfFolder);

mcolFoldercollection.Add(lstrEntryKey, lobjOutlookFolder);

}
}



At start up of my addin by recursive function , inside this ThisAddin.cs
I m creating a wrapper class object for all existing folders iniside
Outlook
and keeping inside a hashtable which is a static member of
outlookFolderWrapper class.

private void AttachEventsForOutlookFolders(ref MAPIFolder vobjmfFolder)
{
int lin = 0;
if (!IsPartOfAddinFolders(vobjmfFolder, ref lint))
{
OutlookFolderWrapper.IsFolderAlreadyExist(ref
vobjmfFolder);

}
for (int i = 1; i <= vobjmfFolder.Folders.Count; i++)
{
MAPIFolder lobjFolder = vobjmfFolder.Folders as
MAPIFolder;
AttachEventsForOutlookFolders(ref lobjFolder);
}

}

This Wrapper function works well if we creates a folder after startup.
Both
FolderAdd and BeforefolderMove event for new folder get fires however on
already exist folder only folderAdd event works means get fires.
beforeFoldermove doens't get fire at all.

Any idea Why out of 2 events only 1 works?

Dmitry Streblechenko said:
You could set up event sinks on each and every folder, but that will
hardly
be efficient. And you will run into problems if you have too many folders
in
an online Exchnage mode. Plus you would need to handle situatiosn when
new
folders are created and old folders are removed.
I would take another look at your app architecture if I were you...

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
At startup , I m attaching 3 events to each all folders inside Outlook

1. BeforeItemMove
2. BeforeFolderMove
3. FolderAdd

Even on BeforeSwitchEvent I am attaching these 3 events to selected
folder.
However these events gets fire only if BeforeSwitchEvents gets fire i.e
when
we are selecting Folder Explicitly.
if I drag folder without selecting it then beforeFolderMove Does't get
fire.
Once folder gets selected and BeforeSwitchEvents gets fire after that ,
its
all three events gets Fire event if don't select it explicitly.

can't be Attach events to folders at startup with recursive functions?


:


Hello Dmitry

For Preventing Item or folder move from or into a Custom folder
I have attached below event for explorer
this.Application.ActiveExplorer().BeforeFolderSwitch += new
ExplorerEvents_10_BeforeFolderSwitchEventHandler(BeforeFolderSwitch);

in BeforeFolderSwitch event attached be these two events.

(vobjMAPIFolder as Folder).BeforeItemMove += new
MAPIFolderEvents_12_BeforeItemMoveEventHandler(BeforeItemMove);
(vobjMAPIFolder as Folder).BeforeFolderMove += new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);

Its work fine if we do explicit folder selection and it fires
BeforeFolderSwitch event
and selectedfolder gets attached with events for beforefoldermove and
before
item move.

however when we drag a folder with out selecting folder then folder
switch
doens't work.
which event of explorer should be use to find selected folder?
I used viewswitch and SelectionChange however its not working for all
condition

:

1. Not unless you write your own store provider
2. Folder.FolderAdd and Folders.FolderRemove events. Keep in mind
that
evenst are not designed for any kind of synchronization: they can be
(and
are) dropped under heavy loads, your code must be listenign to teh
events at
all times, etc.
You can use events as a hint that something happened and you need to
run
your sync sooner rather than later, but they shoudl not be used as a
sole
sync API.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Hello Dmitry

Thanks for reply.

I have 2 more question for MAPI folders

1. Can we make MAPIFolders as disable or unable using c# and VSTO
for
outlook 2007 or outlook 2003?
2. How can we keep a trak of event of folder addintion or move or
delete
from outlook.

I need to keep a watch on if any folder has been added to outlook
,
its
parents.
if any change in parent folder ( in case move).

or folder delete from outlook (Moved to delete folders)

which events I need to listen inside outlook ?


:

Set up the event handler on the currently selected folder, not
your
custom
folder: trap Explorer.FolderSwitch event, set up the
Folder.BeforeItemMove
for the Explorer.CurrentFolder object.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
I attached BeforeITemMove event to my folder class
however this event is fired when I am dragging Mail item out of
our
custom
folder.
I need to captured event when a mailitem dragged into our
custom
folder.

:

Why not use the MAPIFolder.BeforeITemMove event which lets you
cancel
the
operation?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Hello,

We are working on folders creation addin for outlook 2007
using
VSTO.
We are creation set of folders inside add-in.
We have requirement -> not to allow user to drag any
mailitem
inside
our
custom folder before login.
we have created a folderwrapper class and attaction events
 
D

Dmitry Streblechenko

Ah, sorry, the problem is in the following line:

(mobjParentFolder as Folder).BeforeFolderMove+=...

is equivalent to
Folder tempFolder;
tempFolder = mobjParentFolder as Folder;
tempFolder .BeforeFolderMove+=...

there tempFolder is an implicit local variable created by the compiler, and
it will a subject to be released by the GC as soon as OutlookFolderWrapper()
method exists.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Neetu said:
This folder is defined at class level .its a member variable of class with
access modier as private.


Dmitry Streblechenko said:
mobjFolders variable must be alive at all times. You have as a local
vaariables, which means GC will release it whenevre it pleases.
Make it a class member.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Neetu said:
Hello Dmitry

For my below mentioned issue I have another solution not fully working(
need
to find the reason)

I have created a Class called OutlookFolderWrapper.

internal class OutlookFolderWrapper
{
private Folder mobjFolder;

public Folder Folder
{
get { return mobjFolder; }
set { mobjFolder = value; }
}

private Folders mobjFolders;
public Folders FoldersCollection
{
get { return mobjFolders; }
}


private static Hashtable mcolFoldercollection = new Hashtable();
public static Hashtable FolderCollection
{
get { return mcolFoldercollection; }
}


private OutlookFolderWrapper(ref MAPIFolder vobjmfFolder)
{
mobjFolders = vobjmfFolder.Folders;
mobjFolder = vobjmfFolder as Folder;
if (vobjmfFolder.Parent != null)
mobjParentFolder = vobjmfFolder.Parent as MAPIFolder;

if (mobjFolders != null)
mobjFolders.FolderAdd += new
FoldersEvents_FolderAddEventHandler(FolderAdd);

(mobjFolder).BeforeFolderMove += new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);
if(mobjParentFolder!=null)
(mobjParentFolder as Folder).BeforeFolderMove+=new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);
}

public static void BeforeFolderMove(MAPIFolder vobjmfMoveTo, ref
bool
Cancel)
{
int lint = 0;
if (IsPartOfAddinFolders(vobjmfMoveTo, ref lint))
//function
Find if target folder is our addin folder
{
Cancel = true;
System.Windows.Forms.MessageBox.Show("Folder can not
move
to
our Addin folder");
}
}

public static void FolderAdd( MAPIFolder vobjNewFolder)
{
IsFolderAlreadyExist(ref vobjNewFolder);
}

public static void IsFolderAlreadyExist(ref MAPIFolder
vobjmfFolder)
{
string lstrEntryKey = vobjmfFolder.EntryID;
if (mcolFoldercollection.ContainsKey(lstrEntryKey))
mcolFoldercollection.Remove(lstrEntryKey);

OutlookFolderWrapper lobjOutlookFolder = new
OutlookFolderWrapper(ref vobjmfFolder);

mcolFoldercollection.Add(lstrEntryKey, lobjOutlookFolder);

}
}



At start up of my addin by recursive function , inside this
ThisAddin.cs
I m creating a wrapper class object for all existing folders iniside
Outlook
and keeping inside a hashtable which is a static member of
outlookFolderWrapper class.

private void AttachEventsForOutlookFolders(ref MAPIFolder vobjmfFolder)
{
int lin = 0;
if (!IsPartOfAddinFolders(vobjmfFolder, ref lint))
{
OutlookFolderWrapper.IsFolderAlreadyExist(ref
vobjmfFolder);

}
for (int i = 1; i <= vobjmfFolder.Folders.Count; i++)
{
MAPIFolder lobjFolder = vobjmfFolder.Folders as
MAPIFolder;
AttachEventsForOutlookFolders(ref lobjFolder);
}

}

This Wrapper function works well if we creates a folder after startup.
Both
FolderAdd and BeforefolderMove event for new folder get fires however
on
already exist folder only folderAdd event works means get fires.
beforeFoldermove doens't get fire at all.

Any idea Why out of 2 events only 1 works?

:

You could set up event sinks on each and every folder, but that will
hardly
be efficient. And you will run into problems if you have too many
folders
in
an online Exchnage mode. Plus you would need to handle situatiosn when
new
folders are created and old folders are removed.
I would take another look at your app architecture if I were you...

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
At startup , I m attaching 3 events to each all folders inside
Outlook

1. BeforeItemMove
2. BeforeFolderMove
3. FolderAdd

Even on BeforeSwitchEvent I am attaching these 3 events to selected
folder.
However these events gets fire only if BeforeSwitchEvents gets fire
i.e
when
we are selecting Folder Explicitly.
if I drag folder without selecting it then beforeFolderMove Does't
get
fire.
Once folder gets selected and BeforeSwitchEvents gets fire after
that ,
its
all three events gets Fire event if don't select it explicitly.

can't be Attach events to folders at startup with recursive
functions?


:


Hello Dmitry

For Preventing Item or folder move from or into a Custom folder
I have attached below event for explorer
this.Application.ActiveExplorer().BeforeFolderSwitch += new
ExplorerEvents_10_BeforeFolderSwitchEventHandler(BeforeFolderSwitch);

in BeforeFolderSwitch event attached be these two events.

(vobjMAPIFolder as Folder).BeforeItemMove += new
MAPIFolderEvents_12_BeforeItemMoveEventHandler(BeforeItemMove);
(vobjMAPIFolder as Folder).BeforeFolderMove += new
MAPIFolderEvents_12_BeforeFolderMoveEventHandler(BeforeFolderMove);

Its work fine if we do explicit folder selection and it fires
BeforeFolderSwitch event
and selectedfolder gets attached with events for beforefoldermove
and
before
item move.

however when we drag a folder with out selecting folder then folder
switch
doens't work.
which event of explorer should be use to find selected folder?
I used viewswitch and SelectionChange however its not working for
all
condition

:

1. Not unless you write your own store provider
2. Folder.FolderAdd and Folders.FolderRemove events. Keep in mind
that
evenst are not designed for any kind of synchronization: they can
be
(and
are) dropped under heavy loads, your code must be listenign to
teh
events at
all times, etc.
You can use events as a hint that something happened and you need
to
run
your sync sooner rather than later, but they shoudl not be used
as a
sole
sync API.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Hello Dmitry

Thanks for reply.

I have 2 more question for MAPI folders

1. Can we make MAPIFolders as disable or unable using c# and
VSTO
for
outlook 2007 or outlook 2003?
2. How can we keep a trak of event of folder addintion or move
or
delete
from outlook.

I need to keep a watch on if any folder has been added to
outlook
,
its
parents.
if any change in parent folder ( in case move).

or folder delete from outlook (Moved to delete folders)

which events I need to listen inside outlook ?


:

Set up the event handler on the currently selected folder, not
your
custom
folder: trap Explorer.FolderSwitch event, set up the
Folder.BeforeItemMove
for the Explorer.CurrentFolder object.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
I attached BeforeITemMove event to my folder class
however this event is fired when I am dragging Mail item out
of
our
custom
folder.
I need to captured event when a mailitem dragged into our
custom
folder.

:

Why not use the MAPIFolder.BeforeITemMove event which lets
you
cancel
the
operation?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Hello,

We are working on folders creation addin for outlook 2007
using
VSTO.
We are creation set of folders inside add-in.
We have requirement -> not to allow user to drag any
mailitem
inside
our
custom folder before login.
we have created a folderwrapper class and attaction
events
 

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