Trying to get file association to work

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 3387 Views - Last Post: 13 August 2014 - 11:02 PM Rate Topic: -----

#1 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Trying to get file association to work

Posted 13 August 2014 - 04:48 AM

Hey all,

I'm having trouble using file association to open a file that I have previously saved.

The project is a WPF click once application, and here is how I try access the file name

        private void mainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            string[] activationData = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;

            if (activationData != null)
            {
                fileLocation = activationData[0];
            }
        }



In the project Properties > Publish > Application files the .ico file has been included.

In Properties > Publish > Options > File Association the file association has been set up.

Also, the file association is not successfully being implemented on a my computer when I publish the program on it.

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to get file association to work

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,525
  • Joined: 12-December 12

Re: Trying to get file association to work

Posted 13 August 2014 - 04:54 AM

Do you get an error? What error? Or is activationData null?
Was This Post Helpful? 0
  • +
  • -

#3 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 04:57 AM

Because the file association did not work, I tried the "open with" option and tried to use the deployment on my desktop.

Windows reports that the program has stopped working.

Windows reports that the program has stopped working.
Was This Post Helpful? 0
  • +
  • -

#4 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 05:11 PM

File association with a clickonce application seems to be harder than I thought.

I've tried different ways of solving the problem:
http://social.msdn.m...m=winformssetup
Could not find the option

http://blogs.msdn.co...pplication.aspx

http://msdn.microsof...y/bb756929.aspx

http://stackoverflow...a-manifest-file

Made app.manifest...

I am struggling to find anything that works for me.

My goal has not changed: I want is to be able to double click a custom file type and have my program open with that file.

Has anyone had success doing this using WPF/C# and visual studio (express)?
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 6158
  • View blog
  • Posts: 21,236
  • Joined: 05-May 12

Re: Trying to get file association to work

Posted 13 August 2014 - 06:53 PM

Can you please post the contents of your app.manifest?
Was This Post Helpful? 0
  • +
  • -

#6 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 08:05 PM

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Specifying requestedExecutionLevel node will disable file and registry virtualization.
            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="highestAvailable" uiAccess="false" />
      </requestedPrivileges>
      <applicationRequestMinimum>
        <defaultAssemblyRequest permissionSetReference="Custom" />
        <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
      </applicationRequestMinimum>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of all Windows versions that this application is designed to work with. 
      Windows will automatically select the most compatible environment.-->
      <!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
      <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
      <!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
      <!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
    </application>
  </compatibility>
  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
  <!-- <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>-->
</asmv1:assembly>



[edit]
Sorry, that was the one with an error: "ClickOnce does not support the request execution level 'highestAvailable'

Change
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
<requestedExecutionLevel level="asInvoker" uiAccess="false" />



So it is now
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Specifying requestedExecutionLevel node will disable file and registry virtualization.
            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
      <applicationRequestMinimum>
        <defaultAssemblyRequest permissionSetReference="Custom" />
        <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
      </applicationRequestMinimum>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of all Windows versions that this application is designed to work with. 
      Windows will automatically select the most compatible environment.-->
      <!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
      <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
      <!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
      <!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
    </application>
  </compatibility>
  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
  <!-- <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>-->
</asmv1:assembly>


[/edit]
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 6158
  • View blog
  • Posts: 21,236
  • Joined: 05-May 12

Re: Trying to get file association to work

Posted 13 August 2014 - 08:06 PM

Okay... So where is the <fileAssociation> element that you were supposed to stick in there as indicated in the second link that you put in your post?
Was This Post Helpful? 0
  • +
  • -

#8 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 08:12 PM

I've entered that information in Properties > Publish > Options

When I add that information to app.manifest I get the error:

Quote

Error 1 A file association has already been created for extension '.fhc'.

Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 6158
  • View blog
  • Posts: 21,236
  • Joined: 05-May 12

Re: Trying to get file association to work

Posted 13 August 2014 - 08:18 PM

Why not use a different file extension? As noted in some of the other links you posted, if the file extension already has an association, then ClickOnce won't let you setup an association.
Was This Post Helpful? 1
  • +
  • -

#10 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 08:28 PM

I went back to the app.manifest file and added a "1"

i.e.
<fileAssociation xmlns="urn:schemas-microsoft-com:clickonce.v1"
    extension=".tls1"
    description="Log Record"
    progid="TLS.Document"
    defaultIcon="Resources\tlsfileicon_converted.ico"
  />



It is now working.

It is going to take a while to go through each record file I have made and add a "1" to the file extention: Is there a way to remove the .tls and reimplement it?
Was This Post Helpful? 0
  • +
  • -

#11 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 08:43 PM

I tried the method here - http://www.pcadvisor...le-association/

But it didn't seem to work (first problem where windows had to close program)
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 6158
  • View blog
  • Posts: 21,236
  • Joined: 05-May 12

Re: Trying to get file association to work

Posted 13 August 2014 - 08:53 PM

What didn't work? Removing the file association? Or setting up a new association? Or something else?
Was This Post Helpful? 0
  • +
  • -

#13 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 08:57 PM

I went to regedit, removed the file reference
I changed the app.manifest back to .tls
Re-published the clickonce application
re-ran the setup.exe

icon changed for the file type
when I opened the file, I received the same error which I received earlier: Program has stopped working
Was This Post Helpful? 0
  • +
  • -

#14 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 09:07 PM

So now I have 2 entries in FileExts
.tls -> Program always crashes trying to open it
.tls1 -> Opens with program correctly every time.

Is there a way of "copy and pasting" the setting for .tls1 into .tls?
Was This Post Helpful? 0
  • +
  • -

#15 click_here  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 300
  • Joined: 25-November 13

Re: Trying to get file association to work

Posted 13 August 2014 - 09:55 PM

I know that I'm not supposed to, but I manually changed the register file

I copied the string that was in the .tls1 file into the .tls

I then reset the computer

Then I tried to open the .tls file and it crashed, but it also gave me an option (at the same time) to choose a program to open it with. The ClickOnce option was there so I chose that.

I ended up having two windows open: One of them crashed and the other working perfectly.

I closed both down and reopened it - It worked perfectly.

At least now I know that it can work, but I will have to refine the project's file association options to deploy it on other computers
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2