Winform to run and read from a file with a user extension

I am creating a Windows forms application using C #, which should start when a user clicks on a file with a user extension (e.g. filename.mycustomextension) I plan to put the URL in filename.mycustomextension. when the user clicks on this file, we launch the winform application and also read the contents of this file. Can this be done?

+3
source share
3 answers

First of all, you need to associate the file extension with the application, either using "open with" in the shell, either through the installer, or directly in the registry.

MSDN - Best Practices for File Associations

.


   static class Program
    {    
        [STAThread]
        static void Main()
        {
            string[] args = Environment.GetCommandLineArgs(); 
            string text = File.ReadAllText(args[1]);

            // ...
        }
    }

  • args [0] - .
  • args [1] .
  • args [n] - , .

, , WinForms , ...

http://www.hanselman.com/blog/CommentView.aspx?guid=d2f676ea-025b-4fd6-ae79-80b04a34f24c

+5

, .

, , .

:

  • FileAssociation .
  • , .

:

            var FA = new FileAssociation();
            FA.Extension = "blah";
            FA.ContentType = "application/blah";
            FA.FullName = "blah Project File";
            FA.ProperName = "blahFile";
            FA.AddCommand("open", string.Format("\"{0}\" \"%1\"", System.Reflection.Assembly.GetExecutingAssembly().Location));
            //"C:\\mydir\\myprog.exe %1");
            FA.IconPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            FA.IconIndex = 0;
            FA.Create();
+1

, , - .

You just need to install the application on the user machine and associate your .mycustomextension with the application. http://support.microsoft.com/kb/185453

0
source

Source: https://habr.com/ru/post/1730138/


All Articles