Archive for category VSTO

.Net Trust Tribal Knowledge

Caspol is used to setup trusts for .Net applications. But the command line version to view what has been done is not user friendly. A way to view trusts that have been setup can be found in the Microsoft .Net Framework Configuration 2.0 tool. That tool is installed with the .Net SDK. Note: this tool will not be listed in the SDK folder but a shortcut will be added to the Administrative Tools folder on the Program Menu.

Once it is running, check for your trusts that you have setup by looking at this folder

.Netframework 2.0 Configuration\My Computer\Runtime Security Policy\Machine
\ Code Groups

That should list all remote assembly(ies) that one has caspol setting up a trusts for… Note those don’t have to be assemblies but can be a full directory to trust.

By looking at All_Code\LocalIntranet_Zone one can see the pathing to your server as an URL. If you named the trust, it should be easy to find.

Debugging Trust Issues

If when debugging a trust issue, one needs to find the assembly in question as a listing such as \\Server\directory\MyAssembly.dll or within a listing such as \\Server\Directory\* . If that is not found, then trust needs to be setup using CasPol.


  1. One can temporarily turn off caspol security by opening up a DOS shell and typing caspol -s off. While the window is open, caspol will be turned off for debugging purposes. Once the window is closed it will be turned on.
  2. If one has remote assemblies on an intranet directory, one can set the whole directory to be trusted by specify a * when using caspol instead of an assembly or executable. That way if there are multiple assemblies within that directory, you don’t have to specify trust for each one.

Tags: ,

Tribal Knowledge: Working with Office Interops

(Updated 11/22/2011 removed yellow font color)

Most people when working in C# or VB.Net using the VSTO package confuse a VSTO problem with an Interop problem. They are actually quite different. Most of the problems a developer will encounter are actually interops problems with the document they are working on. The problem with the interops is that the documentation of them is sparse and sometimes incomplete. But there is a way to get free fast examples of interop usage and this is the Tribal Knowledge of working with interops:

One way to divine the inner workings of any office document and how to manage it via the interops is to record a macro of the process needed. Once done examine the vba code, it will show settings changes and other items of interest that can lead the way through the tribal knowledge of the interops. Most the object calls are the same under the covers…

If that fails try posting a question to the Microsoft interop groups such as Discussions in Office Development or Discussions in Automation.


C# VSTO Persist Data Between Sessions

I discovered that you can use the Application Settings feature to persist data between application execution sessions for VSTO addins/smart documents. For those not familiar with the Settings object see MSDN’s Using Settings in C#, this is a good place to start. I discovered that a settings file can co-exist with the assemblies installed.

Below is an example where a generic VSTO Excel document is created. A user setting is created and named ColdStorage. It is important in Visual Studio to have that as a user setting so the value can be propagated between user sessions; Otherwise it is an application setting value which is readonly and will fail for our purposes. So set that value.


  1. Create a VSTO Excel document in VS2005.
  2. Create a user setting named ColdStorage as type string.
  3. Copy the below code into the Workbook startup and shutdown method


private void ThisWorkbook_Startup(object sender, System.EventArgs e)

// Write current value from storage to a sheet

Excel.Range rangeB2 = Globals.Sheet1.get_Range("B2", missing);

rangeB2.Value2 = ExcelWorkbookTestSettings.Properties.Settings.Default.ColdStorage;



private void ThisWorkbook_Shutdown(object sender, System.EventArgs e)
    // Read from the sheet and save
    Excel.Range rangeB = Globals.Sheet1.get_Range("B2", missing);

    ExcelWorkbookTestSettings.Properties.Settings.Default.ColdStorage = rangeB.Value2.ToString();