Sunday, February 17, 2008

Problems locating the assembly for Microsoft.Office.Core.DocumentProperties

I am playing around with Word 2007 in Visual Studio 2008.
I was trying to set document properties using code in the form:

( (Microsoft.Office.Core.DocumentProperties) mWordDocument.BuiltInDocumentProperties )[ Word.WdBuiltInProperty.wdPropertyCompany ].Value = "My Company Name";

I had referenced C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.Word.dll which was available in the GAC but I could not find the assembly which contained the definitions for Microsoft.Office.Core.DocumentProperties.

I found it at C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Office.dll

Hope this helps another frustrated searcher.

Detecting Office applications and versions

There may be a way to do this in VSTO.  I would have thought so, but I could not find it!  The linked file contains a C# class to detect office applications and versions.

Wednesday, February 6, 2008

Converting Windows local file paths to uri and vice versa

I needed to covert a windows local file path to a uri in order to pass it to a browser control.

e.g.
I wanted to convert a local windows path in the form:
"C:\Documents and Settings\William Tell\My Documents\TestClient"
to the form:
"file:///C:/Documents%20and%20Settings/William%20Tell/My%20Documents/TestClient"

This conversion is supported by the framwork System.Uri class.
Here is some code:

string localPath = @"C:\Documents and Settings\William Tell\My Documents\TestClient";
Uri uri = new Uri( localPath );
string absoluteUri = uri.AbsoluteUri;


The value of absoluteUri is:
"file:///C:/Documents%20and%20Settings/William%20Tell/My%20Documents/TestClient"

Conversely, we can convert the uri back to a local path as follows:


string absoluteUri = @"file:///C:/Documents%20and%20Settings/William%20Tell/My%20Documents/TestClient";
Uri uri = new Uri( absoluteUri );
string localPath = uri.LocalPath;


The value of local path is:
""C:\\Documents and Settings\\William Tell\\My Documents\\TestClient"

Hope somebody finds this helpful.