If you use
System.IO.Path.GetFullPath(".") from a managed code extension to determine the path of the assembly, you may receive
inconsistent results. Because the value of
GetFullPath(".") depends on the location of the starting process, you might receive different results
when you debug the solution in Visual Studio .NET 2003 than you receive at run time. This article describes how to receive consistent path information for
both Word documents and Excel Workbooks and their associated assemblies.
Microsoft Office Word
- Create a new Microsoft Office System project:
- Start Visual Studio .NET 2003.
- On the File menu, point to New, and then click Project.
- Under Project Types, expand Microsoft Office System
Projects, and then click Visual Basic Projects.
- Under Templates, click Word Document. Name the new
project PathInformationWD. Click OK.
The
Microsoft Office Project Wizard appears. - In the Microsoft Office Project Wizard, click Finish.
- In the new project, add the following code to the ThisDocument_Open event handler:
Dim asm As System.Reflection.Assembly
asm = System.Reflection.Assembly.GetExecutingAssembly()
MsgBox("The location of the assembly: " & asm.CodeBase & vbCrLf & vbCrLf & _
"The location of the document: " & ThisDocument.Path & "\" & ThisDocument.Name)
- Press F5 to build and then run the project.
- When the document opens in Word, a message box appears. Verify the path information for the .NET Framework assembly and the Word document, and then click OK to close the message box.
- Quit Word.
- In Windows Explorer, double-click the Word document PathInformationWD.doc to open the document in Word.
Note This step tests the project at run time. - Verify that the same path information appears in the message box that appeared when you debugged the project in Visual Studio .NET 2003.
Microsoft Office Excel
- Create a new Microsoft Office System project:
- Start Visual Studio .NET 2003.
- On the File menu, point to New, and then click Project.
- Under Project Types, expand Microsoft Office System
Projects, and then click Visual Basic Projects.
- Under Templates, click Excel Workbook. Name the new
project PathInformationXL. Click OK.
The
Microsoft Office Project Wizard appears. - In the Microsoft Office Project Wizard, click Finish.
- In the new project, add the following code to the ThisWorkbook_Open event handler:
Dim asm As System.Reflection.Assembly
asm = System.Reflection.Assembly.GetExecutingAssembly()
MsgBox("The location of the assembly: " & asm.CodeBase & vbCrLf & vbCrLf & _
"The location of the Workbook: " & ThisWorkbook.Path & "\" & ThisWorkbook.Name)
- Press F5 to build and then run the project.
- When the workbook opens in Excel, a message box appears. Verify the path information for the .NET Framework assembly and the Excel workbook, and then click OK to close the message box.
- Quit Excel.
- In Windows Explorer, double-click the Excel workbook PathInformationXL.xls to open it in Excel.
Note This step tests the project at run time. - Verify that the same path information appears in the message box that appeared when you debugged the project in Visual Studio .NET 2003.