# Identify / change working directory for the InstallableNET runtime

I am currently attempting to use .NET/link to call a third party DLL from Mathematica using DLLDefinedFunction. I have been able to link against and call many of the functions in the DLL, but have encountered issues with one function in particular, which attempts to read in data from a file whose path is hard-coded relative to the current working directory.

Forgive my ignorance, but as I am not "au fait" with .NET, I don't know how to determine what InstallableNET32.exe is using as its working directory, or how to change it to something else. (I do know how to change the working directory for the MathKernel, but based on my experimentation, any changes to the kernel's working directory do not appear to "flow through" to the InstallableNET runtime.)

Could someone please provide guidance on how I can identify, and then change, the working directory being used by the InstallableNET runtime (Is this an example of another undocumented feature in .NET/link, like the "Force32Bit"->True option?)

-

I googled ".net change working directory", and this link to Microsoft's .NET docs was the first hit: http://msdn.microsoft.com/en-us/library/system.io.directory.setcurrentdirectory(v=vs.110).aspx. It would suggest the following:

LoadNETType["System.IO.Directory"]
DirectorySetCurrentDirectory["c:\\foo"]


To find out the current working directory:

DirectoryGetCurrentDirectory[]

-
Todd: Thanks, this works. I had tried something similar, but was attempting to load "System.IO" only. I did say I wasn't at all familiar with .NET ... ;-) –  Confused-cius Dec 18 '13 at 18:09

This may be what you're looking for or at least help slightly...

http://msdn.microsoft.com/en-us/library/system.io.directory.setcurrentdirectory(v=vs.110).aspx

You would need to load the System.IO.Directory class and call the static SetCurrentDirectory method on it.

Alternatively I believe you can set it (dim distant memory) in the InstallableNet.exe.xml (or InstallableNET32.exe.xml) file located in C:\Program Files\Wolfram Research\Mathematica\9.0\SystemFiles\Links\NETLink which would then make it a default. If its not set anywhere it defaults to the location the .NET runtime executed from.

-
Ymareth: Thanks. The System.IO.Directory approach works (as also pointed out by Todd above). I had a quick look in the .xml config files you mentioned, but can't confirm or deny whether an appropriate edit in these files would work. –  Confused-cius Dec 18 '13 at 18:47