0

i made C# program that open and show xml files.

how to make (on my program installation) that all *.xml files

that in my computer will opened with my program ?

thanks in advance

Gali
  • 14,511
  • 28
  • 80
  • 105
  • 5
    See http://stackoverflow.com/questions/69761/how-to-associate-a-file-extension-to-the-current-executable-in-c – Bala R Apr 20 '11 at 20:00
  • 2
    Do you want to do it programatically (when installing your application, etc)? or just do it once in your computer manually? – Oscar Mederos Apr 20 '11 at 20:01
  • possible duplicate of [Associate File Extension with Application](http://stackoverflow.com/questions/2681878/associate-file-extension-with-application) – Greg Apr 20 '11 at 20:33

2 Answers2

2

As detailed in this question, you need to change the value of the registry key HKEY_CLASSES_ROOT\xmlfile\shell\open\command on the user's machine.

This could be achieved programatically by code such as (untested):

// Get App Executable path
string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

RegistryKey rkShellOpen = Registry.ClassesRoot.OpenSubKey(@"xmlfile\shell\open", true);
rkShellOpen.SetValue("command", appPath);
Community
  • 1
  • 1
Carlos P
  • 3,928
  • 2
  • 34
  • 50
0

I think he is wanting a way to search the hard drive for all xml files, so that he can then manage them in some sort of tree for easy opening and closing.

You could do something similar to this...

   void RecursiveDirectorySearch(string sDir, string patternToMatch) 
        {
          // Where sDir would be the drive you want to search, I.E. "C:\"
          // Where patternToMatch has the extension, I.E. ".xml"
            try 
            {
                foreach (string d in Directory.GetDirectories(sDir)) 
                {
                    foreach (string f in Directory.GetFiles(d, txtFile.Text)) 
                    {
                       if(f.Contains(patternToMatch)
                        {
                          lstFilesFound.Items.Add(f);
                        }
                    }
                    DirSearch(d);
                }
            }
            catch (System.Exception excpt) 
            {
                Console.WriteLine(excpt.Message);
            }
        }
David C
  • 3,610
  • 3
  • 21
  • 23