Note that there are some explanatory texts on larger screens.

plurals
  1. POproblem with Associate file type in my program
    text
    copied!<p>i have this code for Associate *.sdf files to my C# program:</p> <pre><code> public class FileAssociation { // Associate file extension with progID, description, icon and application public static void Associate(string extension, string progID, string description, string icon, string application) { Registry.ClassesRoot.CreateSubKey(extension).SetValue("", progID); if (progID != null &amp;&amp; progID.Length &gt; 0) using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progID)) { if (description != null) key.SetValue("", description); if (icon != null) key.CreateSubKey("DefaultIcon").SetValue("", ToShortPathName(icon)); if (application != null) key.CreateSubKey(@"Shell\Open\Command").SetValue("", ToShortPathName(application) + " \"%1\""); } } // Return true if extension already associated in registry public static bool IsAssociated(string extension) { return (Registry.ClassesRoot.OpenSubKey(extension, false) != null); } [DllImport("Kernel32.dll")] private static extern uint GetShortPathName(string lpszLongPath, [Out] StringBuilder lpszShortPath, uint cchBuffer); // Return short path format of a file name private static string ToShortPathName(string longName) { StringBuilder s = new StringBuilder(1000); uint iSize = (uint)s.Capacity; uint iRet = GetShortPathName(longName, s, iSize); return s.ToString(); } } </code></pre> <p>and i use it like this:</p> <pre><code> if (!FileAssociation.IsAssociated(".sdf")) FileAssociation.Associate(".sdf", "ClassID.ProgID", "sdf File", @"d:\ICO.ico", @"D:\OpenSDF.exe"); </code></pre> <p>i try this too:</p> <pre><code> if (FileAssociation.IsAssociated(".sdf")) FileAssociation.Associate(".sdf", "ClassID.ProgID", "sdf File", @"d:\ICO.ico", @"D:\OpenSDF.exe"); </code></pre> <p>my problem is when the file Already associated with another program it wont work !</p> <p>for example: the <code>*.sdf</code> files on my computer Associate to open with <code>Visual-studio 2008</code></p> <p>i run this code - <strong>and Nothing happens !!</strong></p> <p>what i can do ?</p> <p>thanks in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload