Ravi Mattar
Ravi Mattar

Reputation: 185

How to use my app to open a file when I double-click it?

I have been searching this for days and days and can't find an answer, and when I find it simply does not work.

So I have a text editor app, and I want to be able to open text files with it just like we do with Windows Notepad. I want it to be able to just double click a file and my application to open and display that file.

I have already set my app as default on Windows, so when I double click a file, my application comes up, but of course with no file.

So I need to get the file path. The answers I found say that the first argument is the path, but with my experience, I think that it just isnt, or I have been doing it wrong, so, how do I get it? Or I shouldnt use arguments? What should I use? All I need is the file path.

EDIT: Just so you guys know, its a Windows forms app. Not console.

Upvotes: 0

Views: 844

Answers (1)

Poma
Poma

Reputation: 8484

Indeed first argument is the file name:

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
                Console.WriteLine(args[0]);
            Console.ReadKey();
        }
    }
}

This program will output name of file you want to open

Upvotes: 1

Related Questions