How to open a folder with the default file-manager in mono/C#

using System.Diagnostics;

Process.Start (“file:///home/”);

Did a bit of IRC channel ping-pong today. Went over to #f-spot to ask a user-related question about f-spot, and got pulled in by curiosity on a totally unrelated topic: opening a folder with the default file-manager. Initiated some discussion on #mono and discovered this was, in fact, not trivial – which seemed odd. But I’ve never personally written any C#, or much desktop code at all, for that matter. So I started playing around with various suggestions from the good folks in #mono, and writing my very first C# application.

(Yeah, basically a one-liner. You gotta start somewhere! ^_^) Anyway, for something so simple, there seemed to be a lot of uncertainty and discussion about it (even from the man, himself! – He claims his memory is fading…), so I figure it’s worth documenting. More info can be seen here under Process.

On FreeDesktop systems it will use xdg-open, if not, it will try to use gnome-open or kfmclient to open the files.

Not sure if this will work on Windows. The file:// prefix is required.

Update: According to ccoish, this will work on Windows.

Passing this info back to #f-spot resulted in a patch to allow you to open the folder containing your photo. Thanks, Gabriel! Open source is cool. 🙂

Not sure if I’ll look at C#/Mono much more, was kinda gonna do the Python thing for a while… but this was a fun distraction. 🙂

2 comments

Leave a comment

Your email address will not be published. Required fields are marked *