Herman Solberg

Hi!

When I deploy my recently built addin I run into problems when. In my code I declare two members that hold the file names of an .xml file and and .xsd file that I use in my addin. These are located in the same folder as my assembly and therefore should be found by just opening them with a relative path. This is how I define the members:

Code Snippet

private const string xmlFile = "Data.xml";
private const string xmlSchema = "Data.xsd";

On startup I want to do the following with these paths:

Code Snippet

XmlDataDocument data = new XmlDataDocument();
data.DataSet.ReadXmlSchema(xsdPath);
data.DataSet.ReadXml(xmlPath);

On my debugging machine this works just fine. On my testing machine the files can't be found because my assembly for some reason look in this directory:

H:\Data.xsd

instead of:

C:\Program Files\<CompanyName>\<SolutionName>\Data.xsd

I can add that the H:\ volume is a network drive mapped to my Active directory account.

Does anyone know how to solve this problem simply Helps will be much appreciated.

//Herman




Re: Visual Studio Tools for Office "Cannot find file" on startup - Word 2003 addin, VSTO 2005 SE

Cindy Meister

How about using System.Environment.CurrentDirectory.ToString to return the folder where the Add-in is installed




Re: Visual Studio Tools for Office "Cannot find file" on startup - Word 2003 addin, VSTO 2005 SE

Herman Solberg

Good tip Cindy!

Unfortunately the same result as before. This time I used the following syntax:

Code Snippet

private string xmlPath = Path.Combine(Environment.CurrentDirectory, "Data.xml");
private string xsdPath = Path.Combine(Environment.CurrentDirectory, "Data.xsd");

Code Snippet

XmlDataDocument data = new XmlDataDocument();
data.DataSet.ReadXmlSchema(xsdPath);
data.DataSet.ReadXml(xmlPath);

It's really strange that it's pointing to the network drive when the assemly is on the hard drive...

Any other ideas anyone

//Herman






Re: Visual Studio Tools for Office "Cannot find file" on startup - Word 2003 addin, VSTO 2005 SE

Herman Solberg

I tried to disconnect the network drive H:\ to see if that made a difference but not it looks for the file in the directory C:\WINDOWS instead...

That also a strange place to look.

//Herman






Re: Visual Studio Tools for Office "Cannot find file" on startup - Word 2003 addin, VSTO 2005 SE

Herman Solberg

After some further digging I came across a methos of getting the path to the executing assembly as a string, so I wrote a property that returns that string. This is what I wrote:

Code Snippet

public string AddinFolder
{
get
{
Assembly *** = Assembly.GetExecutingAssembly();
string location = ***.CodeBase;
location = location.Remove(location.LastIndexOf("/") + 1);

return location;
}
}

And I assinged my string variables like this:

Code Snippet

xmlFile = AddinFolder + "Data.xml";
xmlSchema = AddinFolder + "Data.xml";

Maybe not the most elegant solution but it works anyway.

//Herman