954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can't pass associated file as a command line argument

Hello there,

I am trying to create an application which will open once the associated file type is clicked. I have associated my application with the extension .agl, via Visual Studio. When I publish the application and install it, the file is associated properly with my application and when I double click an .agl file my application starts. However, the file that opened the application, is not passed as a command line argument and so I can't load it!

Does anyone have any idea why the opening file is not passed as a command line argument? Note that I am using Environment.GetCommandLineArgs() to get the arguments.

Thank you

stelman
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

What is coming back from Environment.GetCommandLineArgs() when the program runs?

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

The method returns only the first argument which is the path of the application.

stelman
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

>The method returns only the first argument which is the path of the application.

Of course the first argument will be a path and next will be a name of asso file. Please show us signature of Main() method.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

>The method returns only the first argument which is the path of the application.

Of course the first argument will be a path and next will be a name of asso file. Please show us signature of Main() method.

What I am trying to say, is that the method returns only the path of the application and not the name of the associated file. The application is a WPF application and I can't find the Main() method.

stelman
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

>The application is a WPF application and I can't find the Main() method.

No problem!

string[] args = Environment.GetCommandLineArgs();
   string datafile=""
   if(args.Length==2)
        datafile=args[1];
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

>The application is a WPF application and I can't find the Main() method.

No problem!

string[] args = Environment.GetCommandLineArgs();
   string datafile=""
   if(args.Length==2)
        datafile=args[1];

This is what I am doing. The problem is that the returned string contains only the name of the application and not the path of the associated file opened. I think this has something to do with how I created the associations, and not with the code.

stelman
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: