Solved

File association with my application.

Posted on 2011-02-16
3
860 Views
Last Modified: 2012-05-11
I am trying to open an xml file with my custom winforms application through file associations.
I have the file evoke the application fine, but I need to know what events during application load I would need to override to consume the file and open it in my app.
I have a loadfile method that I use to traditionally open the files with IO objects in .NET.
But this never gets fired when the target "file" get's clicked and the app loads.

Any help would be great,
Mel
0
Comment
Question by:rotovibe
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 34913378
I believe what you need is to create your application to consume command line parameters.

I believe the system starts a new process and passes a file path as an argument

Your application needs to consume these arguments (e.g., file path)

Basicly, you need to modify the Programm cs class and Form1 constructor to consume file.

I didn't test this but worth to try :)

See modified Programm.cs file:
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace TwoForms
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(args[0]));
        }
    }
}

Open in new window

0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 34913383
BTW, you may need error handling if file path is wrong or is missing...
0
 
LVL 15

Expert Comment

by:DonConsolio
ID: 34913404
Try setting a file association from the desiread extension to your application



code example:
http://www.codeproject.com/KB/dotnet/System_File_Association.aspx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question