Programmatically creating auto-format rule in Outlook

Here is the code snippet…

private void AutoFormat()
{
      try
      {
            AutoFormatRule afr;
            TableView tv;
            tv = applicationObject.ActiveExplorer().CurrentView;
            MessageBox.Show(tv.AutoFormatRules.Count.ToString());
            for (int i=1;i<=tv.AutoFormatRules.Count;i++)
            {
                  AutoFormatRule rl =  tv.AutoFormatRules[i];
                  if(rl.Name=="TestAFRule")
                  {
                        tv.AutoFormatRules.Remove(i);
                        MessageBox.Show("Deleted" + rl.Name);
                  }
            }
            afr = tv.AutoFormatRules.Add("TestAFRule");               
            afr.Font.Color = OlColor.olColorRed;                
            afr.Enabled = true;
            tv.Save();
            tv.Apply();
            MessageBox.Show("Done");
      }
      catch(System.Exception ex)
      {
            MessageBox.Show("Err:" + ex.Message);
      }
}

 

Advertisements

Is VSTO still alive?

Yes… you read it right!

Many people talk about Azure, HTML5, SilverLight, WindowsPhone 7, SharePoint etc. How many are talking about VSTO? Compared to other technologies, people who on talk on VSTO might be very less. But, the fact is that VSTO will exist and grow as long as there is a product called Microsoft Office exist!

Many people suggested me to retire from VSTO and choose some other technology as there is not much focus on it. But, VSTO is installed in my mind without ‘Uninstall’ option. Though I work on other technologies like Mobile Apps, ASP.NET etc., I always explore more about VSTO and love to get updates of it.

Actually, VSTO is not that bad as people think. It has very good features which address some issues which can’t be solved by other technologies. Some of the new features on Office 2010 like Backstage View, Ribbon Enhancements, Programmability refinements etc extends the programmability and make it ease.

When I have started working on VSTO, it is not shown in web search results (Bing or Google) until it is typed correctly. But now,  we have got many Video and Text Tutorials, Blogs, MSDN Library, exclusive forums to each office application and lot many. There is a lot of development in VSTO since last two years compared to before.

I thought to write a post on this after reading Ridi’s post – Is VSTO Dead?. Thanks Ridi!

Ridi recently spoke at Microsoft Innovation Roadtrip  and delivered several points on why Office programming is still valuable to give another benefits in organization productivity. He has shared few presentation decks on VSTO. Here is the Live Spaces link for it – http://bit.ly/lgXTk9

You can find Screen Casts, Tutorials and some downloadable content about VSTO 2010 here.

Happy Coding!

PropertyAccessor in Exchange 2010 – issue and some workarounds

Following code works fine in Exchange 2003 and 2007. But fails in Exchange 2010, that too in Online Mode. There is an interesting discussion that happened recently in MSDN Forums on this topic. Just would like to share summary of it so that it will be helpful to them who are in need of it.

As of now, there is not work around, except changing mode of Exchange to Cache Mode. Some told that Microsoft is aware of this issue and working on it. A fix may be released with the next patches.

const string TEST_PROPERTY = @"http://schemas.microsoft.com/mapi/string/
{00020329-0000-0000-C000-000000000046}/TestProperty/00000003";
 const int TEST_VALUE = 9;
 application = new MSOutlook.ApplicationClass();
 email =
(MSOutlook.MailItem)application.CreateItem(MSOutlook.OlItemType.olMailItem);
 propertyAccessor = email.PropertyAccessor;
 propertyAccessor.SetProperty(TEST_PROPERTY, TEST_VALUE);
 object objValue = propertyAccessor.GetProperty(TEST_PROPERTY);

Here is another work around suggested by Joel…

“it looks like the it’s not completely resolved by simply using extended MAPI.  I was trying to use IMAPIProps::GetProps() and specifying a single property tag with the ID specified, but the type not specified (using PT_UNSPECIFIED).  As already noted, this works fine with Exchange 2007 online or cached mode, Exchange 2010 in cached mode, but not in Exchange 2010 online mode.

The workaround in this case is to specify the correct property type.  But, since the managed PropertyAccessor.GetProperty() method does not know what the property type is ahead of time (at least for custom properties), I guess that could be why it’s failing.  What I’m doing now is calling IMAPIProp::GetPropList() and finding the entry with matching property tag.  Since GetPropList() returns the property type as well, I can now call GetProps() with the correct property type.  This seems to work in Exchange 2010 online mode :)”

I think this is the simplest of all (which is suggested by Susanne Kapp via Wompi)…

For an easy workaround in VSTO, you can simply call the mailItem.Save() method after setting the property. But be aware of all the mails getting saved to your drafts folder if you don´t send the mail.

Hope this helps!

Deploying a COM Addin in 64-bit Office

Deployment alone is a hassle for VSTO Developers, especially beginners. In this, if one needs to deploy add-in in a 64-bit system is hectic. Here is a simple solution that I have used to debug and deploy add-ins in 64-bit Office.

You just need to follow these steps.
By default, the add-in will be registered with the respective office application. This is enough to run the application in debug mode. If we select ‘my add-in should be available to all users…’ option, it registers the add-in in the 32-bit global registry. This can be seen in RegEdit like this.
HKLM\Software\Wow6432Node\Microsoft\Office\\AddIns\

But, 64-bit Office cannot see registries in this location. For the add-in to load correctly, the registry keys should be moved to the following location.
HKLM\Software\Microsoft\Office\\AddIns\

For deploying the application…

In Visual Studio 2010, you just need to update the TargetPlatform property to x64 in the Setup Project Properties. Your project is ready to be deployed in 64-bit versions of Office now!

If you are working on Visual Studio 2008, there is a bug in setup project which prevents the add-in from registering 64-bit COM components. A work around is suggested for this problem in Cannot load 64-bit self-registering DLL’s section in Troubleshooting Windows Installer Deployments article in MSDN. It describes how to manually write 64-bit registry keys for making your add-in to work in 64-bit Office.

For more details, go through this article: Deploying COM Add-ins for 64-bit Office using Visual Studio

Key points for updating a deployed office solution

You might have got a requirement to update the existing (deployed) office solution. If so, here are some key points related to signing certificates, that you need to keep in mind before doing this, which are suggested by msdn.

  1. Ensure that the solution is set up to provide the correct evidence for the security checks –
    • If the old solution is signed with a trusted certificate, sign the updated solution with the same certificate. If the certificate has expired or cannot be reused, use a certificate that is trusted at the enterprise level.
    • If the ClickOnce trust prompt was used for trust but the zone has been disabled, the solution will be disabled.
    • If the signing key was changed, trust must be re-established by using the ClickOnce trust prompt, or the certificate must be trusted at the enterprise level. If the trust is pre-established, the first version will be uninstalled and the updated version will be installed.
    • If the new certificate is trusted at the enterprise level, then the update takes place with no prompting.
    • If the new certificate is not trusted, a trust prompt is displayed to the user, if the prompt is allowed.
  2. Use the Publish Wizard to publish the updated Office solution to the same directory as the previous version.
    The Office solution is published to a folder at the same directory level as the old solution, but with an incremented version number. The application and deployment manifests are replaced, so the user is automatically directed to the new version the next time the solution checks for updates.
  3. Copy the solution files to the installation location, if it is different from the publish location. Keep the folders and files in the same relative positions.

Articles: Customizing the Office Ribbon

Just came across the series of articles on Customizing Office Fluent Ribbons for Developers which covers all the customizing options that are available for Developers. Here are their links.

Hope this helps!

Office 2010 Developer Roadmap

Just came across some beautiful videos on Office 2010 Development and would like to share with you.

Introducing Office 2010 – whats new in Office 2010 and its integration with SharePoint

Office 2010 Development Tools – various tools that supports development of office customization and the enhancements in them

Developing Office 2010 Customizations – customizing UI in Office 2010, concepts needed for Office 2010 development on both the server and client

Introduction to Office 2010 Developer Roadmap Module – a brief description of this module

Another noteworthy thing is Development Lab. Go through the link for more details.

Getting Started with Office 2010 Development Lab