1

i have my C# program that can open *.sdf file.

i made Associate to my program.

but how to do this: when i press any *.sdf file (my program opened)

and how i can pass the name & the path of the *.sdf file that i press ?

i want to open this *.sdf file

thanks in advance

Gali
  • 14,511
  • 28
  • 80
  • 105
  • File association works on extension. Unless your program is a database tool you should pick another extension. – H H Apr 22 '11 at 06:54

2 Answers2

4

It should be the first argument string passed to Main():

static void Main(string[] args)
{
   string sdfFileName = args[0];

   using(var connection = new SqlCeConnection("Data Source = "+sdfFileName))
    {
      //connected to SQL Server Compact database (*.sdf)
    }
}
Mark Cidade
  • 98,437
  • 31
  • 224
  • 236
  • OK, and how to pass the name & the path of the file that i press (can be Everywhere) – Gali Apr 22 '11 at 06:27
0

Look into this topic - Associating file extensions with a program
In short words, when you are registering association for your file you should write some registr keys (see link to know which) and in shell open command key you should write command which would run your app and pass file path as command line args. It will looks like "c:\Myapp\app.exe" %1, where %1 translates in full file path at call time. So after that you should use command args as desribed in Mark Cidade's answer

Community
  • 1
  • 1
Anton Semenov
  • 6,227
  • 5
  • 41
  • 69