Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created my WPF single instance click once applcation by using the Microsoft.VisualBasic dll method. However I'm facing some difficulty to get the file path for second clicked file which associated with my app.

For example, I have two file "First.my" and "Second.my". When I click on file "First.my" it will launch my app and pop up message box to show "First.my" file path. Since my app is single instance app, when I click on file "Second.my" it should show the file path for "Second.my" but it still showing the file path for "First.my"..
Does anyone know how to pass the associate file path in single instance app?
Below is my code:

C#
class WindowsFormsApp : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
    private App _wpfApp;

    public WindowsFormsApp()
    {
        IsSingleInstance = true;
    }

    protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
    {
        MessageBox.Show("First File");
        //Get 1st click file path
        GetFilePath();
        _wpfApp = new App();
        _wpfApp.Run();

        return false;
    }

    protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs e)
    {
        MessageBox.Show("Second File");
        //Get 2nd click file path
        GetFilePath();
    }

    protected void GetFilePath()
    {
        if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
           AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
        {
            var filePath = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
            var uri = new Uri(filePath);
            MessageBox.Show(uri.LocalPath);
        }
    }
}
Posted

1 solution

You can get it from the CommandLine property of the StartupNextInstanceEventArgs / StartupEventArgs property.
 
Share this answer
 
Comments
Tina Ng 29-Oct-13 0:47am    
it still show the "First.my" file path

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900