Puil

I want to open an XpathDocument, using a path like this "%programfiles%\MyCompany\MyFile.xml". The problem is that in this way it never points to "C:\Program Files", but to e.g. "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\%program files%\MyCompany\MyFile.xml". I want to use %programfiles% instead of "C:\Program Files", cause I'm deploying to a system where the program files could be located elsewhere. How can this be solved

This is my code:

XPathDocument doc = new XPathDocument("%programfiles%\\Abacus\\PensionPlanner\\PensionTable.xml");




Re: XML and the .NET Framework opening Xpathdocument with an absolute path

Puil

At last I've found a way:

XPathDocument doc = new XPathDocument(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + \\Abacus\\PensionPlanner\\PensionTable.xml);

Works as a charm.






Re: XML and the .NET Framework opening Xpathdocument with an absolute path

Derek Smyth

Hi,

There is an Enviroment enumeration you can use to specify system directories like Program Files, and My Documents, etc. Here is a code snippet that demonstrates....

Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)

returns the program files directory regardless of what drive it is stored on.






Re: XML and the .NET Framework opening Xpathdocument with an absolute path

Robert Rossney

You want to use Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).