Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am develop notepad project and deploy this project. after install this to select windows any text file .right click those file select openwith browse by installed file.
can't read this file .how to read this file directly with out using openfile dailog()
i am using textbox in my project.i am already used openfile dailod() in my notepad.
I want directly open windows text files in my notepad. please help me how to open this files



C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RTM____notepad
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           

           
      }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //textBox1.Clear();
            {

                // check if the text is modified

                if (textBox1.Modified)
                {

                    //if text is modified then ask the user if to save it or not

                    DialogResult ask;

                    ask = MessageBox.Show("Do you want to save the changes", "New Document", MessageBoxButtons.YesNo);

                    {

                        try
                        {

                            //if user clicks No, then notepad will be cleared

                            if (ask == DialogResult.No)

                                textBox1.Clear();

                                // if user clicks yes, save file dialog will appear

                            else if (ask == DialogResult.Yes)

                                saveFileDialog1.ShowDialog();



                            //saving the file process

                            System.IO.StreamWriter file = new System.IO.StreamWriter(saveFileDialog1.FileName, true);

                            string text = textBox1.Text;

                            file.WriteLine(text);

                            file.Close();

                            textBox1.Clear();

                        }

                        catch
                        {

                            MessageBox.Show("you loss the data");

                        }







                    }



                }
            }




        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            System.IO.StreamReader openFile = new System.IO.StreamReader(openFileDialog1.FileName);
            textBox1.Text = openFile.ReadToEnd();
            openFile.Close();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.IO.StreamWriter saveFile = new System.IO.StreamWriter(openFileDialog1.FileName);
            saveFile.WriteLine(textBox1.Text);
            saveFile.Close();
        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {


            saveFileDialog1.ShowDialog();
            System.IO.StreamWriter saveFile = new System.IO.StreamWriter(saveFileDialog1.FileName);
            saveFile.WriteLine(textBox1.Text);
            saveFile.Close();
        }

        private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Printing.PrintDocument prntDoc = new System.Drawing.Printing.PrintDocument();
        }

        private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Printing.PrintDocument prntDoc = new System.Drawing.Printing.PrintDocument();


            //Declare preview as a new PrintPreviewDialog
            PrintPreviewDialog preview = new PrintPreviewDialog();
            //Declare prntDoc_PrintPage as a new EventHandler for prntDoc's Print Page
           // prntDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintPreviw);
            //Set the PrintPreview's Document equal to prntDoc
            preview.Document = prntDoc;
            //Show the PrintPreview Dialog
            if (preview.ShowDialog(this) == DialogResult.OK)
            {
                //Generate the PrintPreview
                prntDoc.Print();
            }


        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // Application.Exit();


            if (textBox1.Modified)
            {

                // if file is modified, then ask if the user want to save the changes

                DialogResult ask;

                ask = MessageBox.Show("Do you want to save the changes", "Exit", MessageBoxButtons.YesNo);

                {

                    try
                    {

                        // if user clicks no, program exits

                        if (ask == DialogResult.No)

                            Application.Exit();

                            // if user clicks yes, program save file

                        else if (ask == DialogResult.Yes)

                            saveFileDialog1.ShowDialog();



                        System.IO.StreamWriter file = new System.IO.StreamWriter(saveFileDialog1.FileName, true);

                        string text = textBox1.Text;

                        file.WriteLine(text);

                        file.Close();

                        Application.Exit();

                    }

                    catch
                    {

                        MessageBox.Show("you loss the data");

                    }



                }

            }

            else

                Application.Exit();

           











        }

        private void undoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Undo();
        }

        private void redoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Undo();
        }

        private void cutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Cut();
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Copy();
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Paste();
        }

        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.SelectAll();
        }

        private void fontToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fontDialog1.ShowDialog();

            textBox1.Font = fontDialog1.Font;
        }

        private void fontColourToolStripMenuItem_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();

            textBox1.ForeColor = colorDialog1.Color;
        }

        private void leftToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.TextAlign = HorizontalAlignment.Left;
        }

        private void centerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.TextAlign = HorizontalAlignment.Center;
        }

        private void rightToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.TextAlign = HorizontalAlignment.Right;
        }

        private void backgroundColourToolStripMenuItem_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();

            textBox1.BackColor = colorDialog1.Color;
        }


       
    }
}


the above program after initialization of frame. It is does not take input. so help this to take input if any windows text file double click to open this file into a my notepad. please help me


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 2-May-12 21:54pm
v2
Comments
DominicZA 3-May-12 3:51am    
Reason for my vote of 1
No formatting, not really sure there is a question in there??
[no name] 3-May-12 7:55am    
How does anything you typed in here related to a URL?

1 solution

If you have associated your program with .TXT files (and I don't see anything there that does) then you need to access the program arguments and get the file name(s) to open.

If you haven't, then you need to do that or windows doesn't know you are supposed to handle TXT files! System File Association[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900