Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > File Association in ClickOnce Applications
 

File Association in ClickOnce Applications

HI,

Just downloaded SP1 for VS2008 and now have the UI bit for file association which is great and means I don't have to manually add it.

What is the point of it though as all it does is launch the application when you double click on the file. The file that launched the application is not passed as an argument so I fail to see the use.

Can anyone explain to me why I would want to setup file association if it doesn't work properly. I have found a way around it by manually changing the file association to launch explorer and a URL, but you need to be admin to do this.

Thanks

Chris

sgibtattutpp  Tuesday, August 26, 2008 10:24 AM

The file name is not passed into main as args, instead they are made available to the application through the ActivationArguments of the current app domain's setup information. To access the arguments, you need code something like this:

Code Snippet

If AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData IsNot Nothing _
AndAlso AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0

Presumably this is necessary because of the way ClickOnce activates the application, but I don't know for sure.
Mike Wade - MSFT  Wednesday, August 27, 2008 4:21 PM

The file name is not passed into main as args, instead they are made available to the application through the ActivationArguments of the current app domain's setup information. To access the arguments, you need code something like this:

Code Snippet

If AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData IsNot Nothing _
AndAlso AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0

Presumably this is necessary because of the way ClickOnce activates the application, but I don't know for sure.
Mike Wade - MSFT  Wednesday, August 27, 2008 4:21 PM

Thanks that worked great below is the code I used to extract the UNC path from the URI path provided just incase anyone was wondering how to do it:-

Code Snippet

string formPath = string.Empty;

if(AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)

{

foreach (string arg in AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData)
{
if(arg.StartsWith("file"))
{

Uri file = new Uri(arg);
formPath = file.LocalPath;
}
}

}

Chris
sgibtattutpp  Thursday, August 28, 2008 8:21 AM

You can use google to search for other answers

Custom Search

More Threads

• ClickOnce hangs at "verifying application requirements..."
• Version information on the first page of install
• Class not registered ??
• Adding an Executable to a Deployment Project
• window AutoScrolling or SelfScrolling
• Invalid value for 'OSVersion'
• Deploying web forms
• Install-time code generation...
• Vista Ultimate; Blue screen when publishing clickonce project
• Deployment project - how do I get a link to my executable within the start>Program Files menu?