Drag&Drop d'un mail Outlook et l'enregistrer.
Bonjour tout le monde,
Je suis entrain de réaliser une application qui à pour but de faire un Drag&Drop d'un e-mail Outlook et de l'enregistrer dans un dossier.
Voici mon code :
Code:
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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Office = Microsoft.Office.Core;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
// e.Effect = DragDropEffects.All;
// Pour ce programme, nous permettons à un fichier à supprimer à partir d'Explorer
if (e.Data.GetDataPresent (DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
// Ou cela nous dit si elle est une baisse de fixation Outlook
else if (e.Data.GetDataPresent ("FileGroupDescriptor"))
e.Effect = DragDropEffects.Copy;
// Ou aucune de ces réponses
else
e.Effect = DragDropEffects.None;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
// Exemple de code prit sur le lien suivant "http://www.developpez.net/forums/d1161973/dotnet/langages/csharp/csharp-sauvegarder-email-fichier-attacher-msg/".
Outlook.MailItem mail = (Outlook.MailItem)selection[1];
mail.SaveAs(@"C:\TEST\test.msg", Outlook.OlSaveAsType.olMSG);
}
}
} |
Malheureusement cela ne fonctionne pas car quand je lance mon application, il m'indique qu'il y a des "erreurs de build" et donc si je ne souhaite pas continuer, voici ce que j'obtiens comme message d'erreur :
Citation:
Erreur 1 Le nom 'selection' n'existe pas dans le contexte actuel C:\Users\utilisateur\Documents\Visual Studio 2010\Projects\DragDropOutlook\DragDropOutlook\Form1.cs
Si je continue, le Drag&Drop se fait mais pas l'enregistrement on dirait.
Quelqu'un pourrait-il m'aider à faire en sorte que ce mail s'enregistre dans le dossier "TEST" s'il vous plaît ?!
Merci par avance.
Loïc.