Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:16:36+00:00 2026-06-15T06:16:36+00:00

Possible Duplicate: How to associate a file extension to the current executable in C#

  • 0

Possible Duplicate:
How to associate a file extension to the current executable in C#

So, I’m making an application for school (final project).

In this application, I have a Project-class.
This can be saved as a custom file, e.g. Test.gpr.
(.gpr is the extension).

How can I let windows/my application associate the .gpr file with this application, so that if I doubleclick the .gpr file, my application fires and opens the file
(so launches the OpenProject method – This loads the project).

I am NOT asking how to let windows associate a file type with an application, I am asking how to catch this in my code in Visual Studio 2012.

UPDATE:
Since my question seems to be not so clear:

atm, I’ve done nothing, so I can follow whatever is the best solution. All I want is to doubleclick the .gpr, make sure windows knows to open it with my app, and catch the filepath in my application.

Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:16:38+00:00Added an answer on June 15, 2026 at 6:16 am

    When you open a file with an application, the path to that file is passed as the first command line argument.

    In C#, this is args[0] of your Main method.

    static void Main(string[] args)
    {
        if(args.Length == 1) //make sure an argument is passed
        {
            FileInfo file = new FileInfo(args[0]);
            if(file.Exists) //make sure it's actually a file
            {
               //Do whatever
            }
        }
    
        //...
    }
    

    WPF

    In case your project is an WPF application, in your App.xaml add a Startup event handler:

    <Application x:Class="WpfApplication1.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml"
                 Startup="Application_Startup"> <!--this line added-->
        <Application.Resources>
    
        </Application.Resources>
    </Application>
    

    Your command line arguments will now be in e.Args of the Application_Startup event handler:

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        if(e.Args.Length == 1) //make sure an argument is passed
        {
            FileInfo file = new FileInfo(e.Args[0]);
            if(file.Exists) //make sure it's actually a file
            {
               //Do whatever
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to associate a file extension to the current executable in C#
Possible Duplicate: php loop through associative arrays i have this piece of code which
Possible Duplicate: Parse a JavaScript file through PHP I have some pretty long string
Possible Duplicate: How to extract a file extension in PHP? I need to build
Possible Duplicate: Entity Framework: There is already an open DataReader associated with this Command
Possible Duplicate: php loop through associative arrays i have a variable which prints an
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Length of Javascript Associative Array I have a JSON that looks like
Possible Duplicate: Workflow for statistical analysis and report writing I have been programming with
Possible Duplicate: ExecuteScalar returns null or DBNull (development or production server) I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.