4

I have created Outlook 2010 addin in visual studio 2012. Which have a context menu and drag and drop area.

I have created its installer file. when I install it in PC which having outlook 2013 it was not working.

How can I create Outlook version independent add in which can work on every version of Outlook.?

Any help for this will be appreciated...!

Rahul Gokani
  • 1,688
  • 5
  • 25
  • 43
  • I've had problems installing an Excel AddIn because Excel 2013 was opened. Did you make sure all instances of outlook were closed before installing your AddIn? – dee-see Nov 29 '13 at 19:10
  • Yes.. I have closed all the instance of outlook... – Rahul Gokani Nov 30 '13 at 04:11
  • 1
    could you add some logging statements to your code to determine if your add-in is loaded at all? If you look up the add-in in Outlook's add-in list, is it active? deactivated? If it's deactivated what's the reason for that? (I've written an add-in that works from Outlook 2007 to Outlook 2013 without any problems, in Outlook 2010 and 2013 it'll use a RibbonMenu, in 2007 it's using a 'normal' menu) – Steffen Winkler Nov 30 '13 at 11:27
  • Check out this page: http://stackoverflow.com/questions/18250511/cannot-debug-or-run-word-addin-because-the-required-version-of-microsoft-office worked for me! – anhoppe Feb 14 '14 at 21:30

3 Answers3

0

Most Office/Outlook 2013 installations are done via Click-to-Run (C2R) as opposed to MSI. MSI was the installation method for most installations of 2010 and earlier.

Your add in needs to be able to detect C2R and account for it when installing.

Jay Lee
  • 13,415
  • 3
  • 28
  • 59
0

According to Microsoft,

If you want to develop an Outlook 2010 addin etc., you can use Visual Studio 2010 or Visual Studio 2012.

If you want to develop an Outlook 2013 addin etc., you can only use Visual Studio 2013.

http://msdn.microsoft.com/en-us/office/hh133430.aspx

Vizllx
  • 9,135
  • 1
  • 41
  • 79
  • Yes I also had read that article. But in my case as I have Context menu and a drag and drop area I have developed the add-in in Visual Studio 2010 and it is working. – Rahul Gokani Dec 02 '13 at 05:06
0

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...!

Rahul Gokani
  • 1,688
  • 5
  • 25
  • 43