.NET Framework General Reference
<fileAssociation> Element (ClickOnce Application)

Identifies a file extension to be associated with the application.

<fileAssociation
    xmlns="urn:schemas-microsoft-com:clickonce.v1"
    extension
    description
    progid
    defaultIcon
/>
Elements and Attributes

The fileAssociation element is optional. The element has the following attributes.

Attribute

Description

extension

Required. The file extension to be associated with the application.

description

Required. A description of the file type for use by the shell.

progid

Required. A name uniquely identifying the file type.

defaultIcon

Required. Specifies the icon to use for files with this extension. The icon file must be specified by using the <file> Element (ClickOnce Application) within the <assembly> Element (ClickOnce Application) that contains this element.

Remarks

This element must include an XML namespace reference to "urn:schemas-microsoft-com:clickonce.v1". If the <fileAssociation> element is used, it must come after the <application> element in its parent <assembly> Element (ClickOnce Application).

ClickOnce will not overwrite existing file associations. If a file extension is already associated with an application, it will not be changed.

Example

The following code example illustrates fileAssociation elements in an application manifest for a text editor application deployed using ClickOnce. This code example also includes the <file> Element (ClickOnce Application) required by the defaultIcon attribute.

  <file name="text.ico" size="4286">
    <hash>
      <dsig:Transforms>
        <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
      </dsig:Transforms>
      <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
      <dsig:DigestValue>0joAqhmfeBb93ZneZv/oTMP2brY=</dsig:DigestValue>
    </hash>
  </file>
  <file name="writing.ico" size="9662">
    <hash>
      <dsig:Transforms>
        <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
      </dsig:Transforms>
      <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
      <dsig:DigestValue>2cL2U7cm13nG40v9MQdxYKazIwI=</dsig:DigestValue>
    </hash>
  </file>
  <fileAssociation xmlns="urn:schemas-microsoft-com:clickonce.v1" extension=".text" description="Text  Document (ClickOnce)" progid="Text.Document" defaultIcon="text.ico" />
  <fileAssociation xmlns="urn:schemas-microsoft-com:clickonce.v1" extension=".writing" description="Writings (ClickOnce)" progid="Writing.Document" defaultIcon="writing.ico" />
See Also

Reference

Tags :


Community Content

emgee
Accessing associated files

Associated files do not come in on the command line, as you might expect. If your clickonce app is activated through a file association, use

AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData

to get the details.

Tags :

brendan_maclean
One more note on associated files
The comment above was the breakthrough I needed to get moving on actually opening ClickOnce associated files. Of course I was trying to modify Program.Main() to accept 'string[] args', and the debugger was complaining:

"The current project settings specify that the project will be debugged with specific security permissions. In this mode, command line arguments will not be passed to the executable. Do you want to continue debugging anyway?"

As it will, if you have published your ClickOnce deployment. Hopefully some of this description will help others find the tip above more quickly than I did.

My added note is that ActivationData is a sting[], and hence tempting to assume it passes an array of file paths, but they are actually in URI format. You'll need something like the following:

string[] args = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
if (args != null && args.Length != 0)
{
try
{
Uri uri = new Uri(args[0]); // SDI only allows one file
if (!uri.IsFile)
throw new UriFormatException("The URI " + uri + " is not a file.");

newFile = !OpenFile(uri.AbsolutePath);
}
catch (UriFormatException)
{
MessageBox.Show("Invalid file specified.", Program.Name);
}
}

Tags :

sandør
get rid of url encoding (%20, file:// and /)

You may want to use Uri.LocalPath instead of Uri.AbsolutePath.

Tags :

Page view tracker