Bonjour à tous
Je voudrais à partir d'une petite appli , deplacer les mails lus dans outlook d'un repertoire à un autre.
je travaille avec visual studio 2008 et la version outlook installée sur mon pc est outlook 2003.
J'ai trouver ce bout de code sur msdn :
j'ai conçu ce projet à partir d'un complement outlook 2003 .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 ---------------------------------------------- using System; using System.Windows.Forms; using Microsoft.VisualStudio.Tools.Applications.Runtime; using Outlook = Microsoft.Office.Interop.Outlook; using Office = Microsoft.Office.Core; namespace ProspectCleanCompOutllook2003 { public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { this.Application.NewMail += new Microsoft.Office.Interop.Outlook. ApplicationEvents_11_NewMailEventHandler (ThisAddIn_NewMail); } private void ThisAddIn_NewMail() { Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)this.Application. ActiveExplorer().Session.GetDefaultFolder (Outlook.OlDefaultFolders.olFolderInbox); Outlook.Items items = (Outlook.Items)inBox.Items; Outlook.MailItem moveMail = null; items.Restrict("[UnRead] = true"); Outlook.MAPIFolder destFolder = inBox.Folders["Old_Prospect"]; foreach (object eMail in items) { try { moveMail = eMail as Outlook.MailItem; if (moveMail != null) { string titleSubject = (string)moveMail.Subject; if (titleSubject.IndexOf("Test") > 0) { moveMail.Move(destFolder); } } } catch (Exception ex) { throw; } } } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } #region Code généré par VSTO /// <summary> /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas /// le contenu de cette méthode avec l'éditeur de code. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion } } ---------------------------------------------------
le pb c'est à la compil, ça plante avec le message :
impossible de charger
Partager