views:

38

answers:

2

In my project properties I go to publish, options, and file associations and enter ".cms", "Contact manager File" "pqcms" and "1icon.ico", but when I publish and install it does not appear to associate the files...I want to be able to double click on the file and have it open the program but it does not appear to do so.

I believe there are ways to edit the registry if you run your program as an administrator, but I really need clickonce to be happy with me because I am maximizing the features. Isn't clickonce supposed to set up the file association for me? Why isn't it?

and final question: what can I do without elevating privileges to administrator?

+2  A: 

Have you added the code required to handle the user double-clicking on the file?

//Get the ActivationArguments from the SetupInformation property of the domain.
string[] activationData =
  AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
if (activationData != null)
{
    Uri uri = new Uri(activationData[0]);
    string fileNamePassedIn = uri.LocalPath.ToString();
    //now you have the file name and you can handle it 
}
RobinDotNet
I have added code to ReadArgsParameterFromCommandLine if that's what you mean.
Assimilater
oops, wrong one "GetCommandLineArgs"
Assimilater
ClickOnce doesn't receive and process arguments the way that regular [exe] files do, so you can't run the [exe] file and pick up the arguments. If you just run the [exe] file, it doesn't run as a ClickOnce app, i.e. no updates, no security checking, etc. The above shows how to get the file name passed in when the user double-clicks on an associated file.
RobinDotNet
I see. Thanks! I'll know if it works when I can double click...so I do I do that?
Assimilater
You have to run it as a deployed application. So add the code, put in a messagebox to show you the file name (or do whatever you're going to do with it), deploy the update, install the application. Then you should be able to double-click on the file and it should pick up the file name and do whatever you have it do.
RobinDotNet
Is deploying the application different than publishing it?
Assimilater
I tried publishing it, then installing the program, thought it does not appear to recognize cms files...I'll try rebooting...lol
Assimilater
I presume it's supposed to work...so I wonder what's going on...it won't even let me manually select the program to open it with...
Assimilater
ok, so I uninstalled it, deleted .cms from the registry (it only had one of the four keys it needed) then rebooted, then republished, then reinstalled and NOW it works. Thanks
Assimilater
You're welcome. I'm glad you got it to work. It's a pretty cool feature.
RobinDotNet
A: 

One other thing to beware of. I originally converted this code (provided by RobinDotNet) to vb.net. Now I've converted the project to c# and ran into something interesting. When debugging (and I'd imagine if you chose to have the exe accessible as opposed to the click once reference app) "AppDomain.CurrentDomain.SetupInformation.ActivationArguments" is null (no activation arguments were assigned) so I modified the code slightly to trap this error.

            //Get the ActivationArguments from the SetupInformation property of the domain if any are set.
        if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null)
        {
            string[] activationData =
              AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
            if (activationData != null)
            {
                Uri uri = new Uri(activationData[0]);
                string fileNamePassedIn = uri.LocalPath.ToString();
                //now you have the file name and you can handle it 
            }
        }
Assimilater