Steffen Winkler is Right. I have find the way that my add in can work on outlook 2010 and 2013.
My add-in contains a Drag and Drop area and Context menu as I have mentioned. I have created Ribbon context menu which can work on both of the outlook.Though I don't have source of outlook 2007 It is remains to test on that.
And for drag and drop area there was a minor change that when I drop mail of outlook 2013 they were bigger in size than the outlook 2010 mails. So I had a class in that I just change the conversion type of the mail to Int64
so that can convert both the mail.
Here is some code for drag and drop area :
private void DragNDropArea_DragDrop(object sender, DragEventArgs e)
{
//wrap standard IDataObject in OutlookDataObject
OutlookDataObject dataObject = new OutlookDataObject(e.Data);
//get the names and data streams of the files dropped
string[] filenames = (string[])dataObject.GetData("FileGroupDescriptorW");
MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents");
for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
{
try
{
//use the fileindex to get the name and data stream
string filename = filenames[fileIndex];
MemoryStream filestream = filestreams[fileIndex];
string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
if (Directory.Exists(startupPath))
{ }
else
{
Directory.CreateDirectory(startupPath);
}
//save the file stream using its name to the application path
FileStream outputStream = File.Create(startupPath + "\\" + filename + ".msg");
filestream.Seek(0, SeekOrigin.Begin);
filestream.WriteTo(outputStream);
outputStream.Close();
filestream.Close();
readMessage(filename, startupPath);
}
catch (System.Exception ex)
{
MessageBox.Show("Error Occured In getting Mail info..: \n" + ex.ToString());
}
}
}
OutlookDataObject.cs
class's GetData()
method:
//create a new array to store file names in of the number of items in the file group descriptor
string[] fileNames = new string[fileGroupDescriptor.cItems];
//get the pointer to the first file descriptor
IntPtr fileDescriptorPointer = (IntPtr)((Int64)fileGroupDescriptorAPointer + Marshal.SizeOf(fileGroupDescriptorAPointer));
//loop for the number of files acording to the file group descriptor
for (int fileDescriptorIndex = 0; fileDescriptorIndex < fileGroupDescriptor.cItems; fileDescriptorIndex++)
{
//marshal the pointer top the file descriptor as a FILEDESCRIPTORA struct and get the file name
NativeMethods.FILEDESCRIPTORA fileDescriptor = (NativeMethods.FILEDESCRIPTORA)Marshal.PtrToStructure(fileDescriptorPointer, typeof(NativeMethods.FILEDESCRIPTORA));
fileNames[fileDescriptorIndex] = fileDescriptor.cFileName;
//move the file descriptor pointer to the next file descriptor
fileDescriptorPointer = (IntPtr)((Int64)fileDescriptorPointer + Marshal.SizeOf(fileDescriptor));
}
This is how I achieve Drag and Drop mail section.
And for the Context menu:
Ribbon1.xml file:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load" loadImage="GetImage">
<contextMenus>
<contextMenu idMso="ContextMenuMailItem">
<button id="MyContextMenuMailItem"
label="OnePgr Integrator"
onAction="OnMyButtonClick" showImage="true" image="favicon.ico.ico"/>
</contextMenu>
<contextMenu idMso="ContextMenuMultipleItems">
<button id="MyContextMenuMultipleItems"
label="OnePgr Integrator" image="favicon.ico.ico"
onAction="OnMyButtonClick"/>
</contextMenu>
</contextMenus>
</customUI>
Ribbon1.cs class :
public void OnMyButtonClick(Office.IRibbonControl control)
{
try
{
Outlook.Selection selectedMails = control.Context as Outlook.Selection;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
From this selection object I can get MailItem which is working on both of the Outlook 2010 and 2013.
Thank you every one for your answers...!