Troubleshooting Office 2007 Add-ins

Here are few links on troubleshooting Office 2007 and 2010 Add-ins which I just came across. I believe that one can get quick work-around to solve ( at least pin-down) the issue.

  • How to: Re-enable an Add-in That Has Been Disabled
  • Debugging in Application-Level Projects
  • Troubleshooting Run Time Errors in Office Solutions
  • Hope this helps!

    Advertisements

    intereSTRINGS

    ‘inetreStrings’ – liked the nomenclature and the sense of humor of the author of it very much.

    String vs string
    Lower case string is simply an alias for System.String in the .NET Framework.

    == or .Equals
    A rule of thumb is that for almost all reference types e.g. objects, use Equals when you want to test equality. == compares whether two references (i.e. object instances) refer to the same object.
    Primitive types can be compared for equality using ==, but in the case of strings, the variables on each side of the operators must be of type string.

    Have a look at the following code and output, taken from Jon Skeet’s blog.

    01    using  System;
    02    
    03    public class Test
    04    {
    05    static void Main()
    06    {
    07    // Create two equal but distinct strings
    08    string a = new string(new char[] {'h', 'e', 'l', 'l', 'o'});
    09    string b = new string(new char[] {'h', 'e', 'l', 'l', 'o'});
    10    
    11    Console.WriteLine (a==b);
    12    Console.WriteLine (a.Equals(b));
    13    
    14    // Now let's see what happens with the same tests but
    15    // with variables of type object
    16    object c = a;
    17    object d = b;
    18    
    19    Console.WriteLine (c==d);
    20    Console.WriteLine (c.Equals(d));
    21    }
    22    }
    23    The results are:
    24    
    25    True
    26    True
    27    False
    28    True

    @ before a string
    Using @ before a string means the escape sequences are not processed. This making it easier to write fully qualified path names for example.
    @”c:\Docs\Source\a.txt” // rather than “c:\\Docs\\Source\\a.txt”

    Stringbuilder
    String objects are immutable, and so editing them, using Replace for example, results in a entirely new string being created, with new memory allocation. The original string is left intact in memory.
    The StringBuilder class is designed for situations when one needs to work with a single string and make an arbitrary number of iterative changes to it. New memory allocation is not needed.

    Came across the above on Bishop’s Blog while searching about something related to VSTO.

    Developing add-ins for multiple versions of Office

    Do you want to develop an add-in targeting multiple versions of Office? And you have basic questions like “Is it possible to do? ” and “How to do it?” ? Then you came to the right place. Few months back, I got a requirement to developed add-ins for Outlook 2003 and Outlook 2007. The functionality for both the versions is same. A doubt stroked… when the functionality is same, why would I develop two add-ins separately? Why don’t I make a single build for both the versions of Office?

    Then I started searching for techniques to develop add-ins which works in both (2003 and 2007) and read many articles written by VSTO Experts in their blogs, Official VSTO Blog, MSDN, Forums and what not.

    Misha Says:

    Theoretically, you can develop an add-in for multiple versions of Microsoft Office by catering to the lowest common denominator. This means if you use an Excel 2003 add-in template in Visual Studio 2008, you would be able to develop and debug this with Excel 2007. However if you try this, you may meet these error messages: “You cannot debug or run this project, because the required version of the Microsoft Office application is not installed.”, followed by “Unable to start debugging.”

    You can develop Office 2003 add-in in a system where Office 2007 is installed. The following is the procedure that demonstrates how to update your Visual Studio debugging options to use Microsoft Outlook 2007 to debug an add-in targeting Microsoft Outlook 2003.

    1. On the Project menu, click on ProjectName Properties
    2. Click on the Debug tab
    3. In the Start Action pane, click the Start external program radio button
    4. Click the file browser button and navigate to %ProgramFiles%\Microsoft Office\Office12
    5. Choose Outlook.exe and click Open
    6. Press F5 to debug your add-in

    For more details. Go through this article in Misha Shneerson’s Blog.

    There are some tips and tricks to be followed and the things that one needs to take care while developing add-ins targeting multiple versions of Office in Andrew’s Blog. Have a look at this too. You might find it interesting and useful.

    http://blogs.msdn.com/andreww/archive/2007/06/15/can-you-build-one-add-in-for-multiple-versions-of-office.aspx

    Here is an MSDN article on Running Solutions in Different Versions of Microsoft Office

    http://msdn.microsoft.com/en-us/library/bb772080.aspx

    Hope this helps!

    Importing an EML File into Outlook

    I am trying to create a mail item in Outlook with old date and time, which looks some thing like an Inbox Mail Item which arrived long back. After some painful hours of searching and reading forums, 3rd party libraries, somehow, I got a solution to do this and would like to share it with you here.

    Here you go!

    Sub CreateMailFromEML()

    Dim objPost As Outlook.PostItem
    Dim objSafePost As Redemption.SafePostItem
    Dim objNS As Outlook.NameSpace
    Dim objInbox As Outlook.MAPIFolder
    Const PR_ICON_INDEX = &H10800003

    Try

    objNS = Application.GetNamespace(“MAPI”)
    objInbox = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    objPost = objInbox.Items.Add(Outlook.OlItemType.olPostItem)
    objSafePost = CreateObject(“Redemption.SafePostItem”)
    objPost.Save()
    objSafePost.Item = objPost
    objSafePost.Import(“c:\SampleEml.eml”, RedemptionSaveAsType.olRFC822)
    objSafePost.MessageClass = “IPM.Note”
    ‘ remove IPM.Post icon
    objSafePost.Fields(PR_ICON_INDEX) = String.Empty
    objSafePost.Save()

    Catch ex As Exception

    MessageBox.Show(“Error: ” & ex.ToString)

    Finally

    objSafePost = Nothing
    objPost = Nothing
    objInbox = Nothing
    objNS = Nothing

    End Try

    End Sub

    Notes:

    • We have to create an instance of Outlook.PostItem instead of Outlook.MailItem.
    • We can also do it using RDOMail which is much simpler than this. (I will discuss about this in separate post).

    I have created the mail item with old date time stamps, attachments successfully. But, couldn’t reset the icon of the PostItem that is created. Searching for a solution to it . Will update it in this post once I got that.

    Today I am on MSDN Forum :)

    Hurray… Today I am in the list of Top Answerers of the Month in VSTO Forum of MSDN. I am enthralled to see my name in such a great and universal Forum 🙂

    This kind of things really incite interest in entrants like me to contribute more to the community.

    Usually I visit Forum to get solutions to the problems faced by me. Some times, when I came across the problem which I have already faced, I will respond. But, these days, answering became a hobby of mine. When ever I get time, I am logging in and answering the forum posts, if I know the answer.

    Here is a snapshot of the Top Answerers List taken from VSTO Forum on MSDN.

    Awesome article on VSTO

    Just came across an awesome article on ‘Visual Studio Tools for Office‘ written by Craig Bailey in his blog CraigBailey.net. Its a brief story of VSTO narrated in simple words so that even beginners can understand it.

    The post is written in interactive manner covering useful points like

    • What is VSTO?
    • Why VSTO?
    • How to start working with VSTO?
    • Some misconceptions on VSTO
    • Hurdles with VSTO

    I am very much impressed with the article and would recommend this to VSTO entrants and enthusiasts to get a clear view of it. Hope you too will like it!

    By the way, where is the link?

    Here is it… 🙂

    http://www.craigbailey.net/clarity-visual-studio-tools-for-office-vsto/

    How to get Sender Email Address from MailItem in Exchange Accounts?

    For getting Sender Email of a MailItem in POP3/SMTP accounts if pretty easy. We can get that by olMailItem.SenderEmailAddress. But, for Exchange Accounts, its  a bit different. We need to get the AddressEntry first and then get the SMTP Address from that object. Here is a sample code that I framed for simpler understanding.

    Dim objSender As Outlook.Recipient = Nothing
    Dim objPropXR As Outlook.PropertyAccessor = Nothing
    Dim strSMTPAddress As String = “”
    Dim strSenderEntryID As String = “”
    Dim objNS As Outlook.NameSpace = Nothing
    Dim objAE As Outlook.AddressEntry = Nothing
    Dim objEU As Outlook.ExchangeUser = Nothing

    objNS = Globals.ThisAddIn.Application.GetNamespace(“MAPI”)
    objPropXR = objMail.PropertyAccessor
    strSenderEntryID = objPropXR.BinaryToString(objPropXR.GetProperty(“http://schemas.microsoft.com/mapi/proptag/0x0C190102”))
    objSender = objNS.GetRecipientFromID(strSenderEntryID)
    objAE = objSender.AddressEntry
    If objAE.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry Then
    objEU = objAE.GetExchangeUser
    strSMTPAddress = objEU.PrimarySmtpAddress
    Else
    strSMTPAddress = objAE.Address
    End If
    MessageBox.Show (“Sender Email Address: ” & strSMTPAddress)

    objMailItem is an object of Outlook.MailItem

    Hope this helps!