I am trying to make file association between an application installed with clickonce and the files with a given extension. I am using Publish Options - File Associations from the project properties to associate the files, as follows:
This works, I can see the files are associated after installing the application, the icon added is visible on the files with the given extension.
Now I am trying to open the files with a Open option within the application, so I have made a simple call to ShowDialog()
method on an OpenFileDialog
object as follows:
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "test files|*.test1";
openFileDialog1.Title = "Select a test file";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
}
The dialog is shown properly, I am able to see the files, but the only problem is that the file icons are shown as blank, as they were not ever associated.
Please notice that in the above picture the file is shown with a blank icon. If I view the file with Windows Explorer it has an image, so I don't really know what is happening or how could I solve it.
Note: I just realized that if I view the same file with Open option from Paint, the file icon is shown properly, but the same open with Microsoft Excel behaves the same as my application, not showing the file icon, so I start to wonder if this could be a bug. Any advice is appreciated!
As Hans Passant pointed out, there was a mismatch between the bit architecture of the process that was running the OpenFileDialog
and the architecture on which the file association was made.
When the application was published with clickonce, the Prefer 32-bit checkbox under Build property was left checked as default so on the x64 machines the clickonce installer was making the file association under the 64 bit registry but the application was still running in 32 bit mode. Because of this mismatch some applications that were build on 32 bit architecture were not able to see the file associations in file dialog.
Unchecking the Prefer 32-bit has solved the problem for me, as both the clickonce installer and the application are now running on the same architecture.