[Mono-list] Platform neutrality and finding where an application is

Chris Howie cdhowie at gmail.com
Fri May 2 11:58:17 EDT 2008


On Fri, May 2, 2008 at 10:55 AM, Paul <paul at all-the-johnsons.co.uk> wrote:
> Hi,
>
>  I need to read and write files out of a program I'm tinkering with, but
>  I have to ensure that it makes no difference as to the platform it's
>  on.
>
>  To this end, I have the file either next to the exe (same directory) or
>  in Resources/file.xml - problem is that while this is fine under Linux,
>  it would have to be Resources\file.xml in Win32.
>
>  Is there a way that I can read/write and let the runtime decide the host
>  platform?

string location = System.IO.Path.Combine("Resources", "file.xml");

>  Is there also a way to find out where the application is running from
>  (for example /usr/bin/application.exe or My Documents\Somewhere
>  \application.exe)?

// For the directory the application was started in.  This may not be
the directory containing the application.
string working_directory = System.Environment.CurrentDirectory;

// The entry assembly's location.
string assembly_location =
System.Reflection.Assembly.GetEntryAssembly().Location;

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers


More information about the Mono-list mailing list