Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
ClickOnce Reference
 <fileAssociation> Element
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.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
/>

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.

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.

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" />
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Accessing associated files      emgee   |   Edit   |   Show History

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 What's this?: Add a tag
Flag as ContentBug
One more note on associated files      brendan_maclean   |   Edit   |   Show History
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 What's this?: Add a tag
Flag as ContentBug
get rid of url encoding (%20, file:// and /)      sandør   |   Edit   |   Show History

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

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker