0

I know there are thousands of this type of question on S.O but i haven't found an appropraite solution that suits my problem.

I have a simple text file create creator that saves file using the default extension .tj. I did this using

    DialogResult DR = openFile.ShowDialog();
    if (DR == DialogResult.OK)
    {
         StreamWriter writeFile = new StreamWriter(new FileStream(openFile.FileName,FileMode.CreateNew,FileAccess.Write));
         writeFile.WriteLine(rtbText.Text);
         writeFile.Flush();
         writeFile.Close();
    }

This works perfectly but what i want is that whenever my Application is installed and a file with the default extension is saved, Whenever the file is Double Clicked, the file opens in my Application and the Rich Text Box shows the text in the file.

Any help will be appreciated

  • 3
    Do you mean that you want your application to register itself as the default program for a certain file type? I'm not sure exactly how that's accomplished, but it looks like there might be an API for it: http://msdn.microsoft.com/en-us/library/windows/desktop/cc144154.aspx – David Jul 20 '13 at 14:48
  • This answer should work as well: http://stackoverflow.com/questions/69761/how-to-associate-a-file-extension-to-the-current-executable-in-c-sharp – Ted Jul 20 '13 at 14:52

1 Answers1

1

If you're using click once deployment, there is a way. You can specify file type associations in your installer and these will be put on the target machine for you. Once they launch a file with that association, your app will start. Taken from this MSDN article. If you're using Nullsoft's NSIS installers, you can do something similar, taken from this file type association article

From here, take the answer from this question to grab the string of the file. Then use a StreamReader or similar to read the file's contents and put them in to the rich text box. Voila!

Hope this helps and let me know if you need any clarification.

Community
  • 1
  • 1
Craig Brett
  • 2,295
  • 1
  • 22
  • 27