开发者

Challenges with Associating files

开发者 https://www.devze.com 2023-01-03 06:05 出处:网络
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

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 u开发者_运维问答p the file association for me? Why isn't it?

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


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 
}


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 
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消