Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7814659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:15:47+00:00 2026-06-02T05:15:47+00:00

my program below is a simple windows form that searches for a file in

  • 0

my program below is a simple windows form that searches for a file in the directory then it opens,reads and writes on it after that there is a search button which searches for words in the file but i can only do this with files that have a .txt extension can some help me i want to do this to word documents as well,i want to open files with .txt and .doc extensions if the file is another extension i want to pop up an error that it can not open the file this is my code below, is there anyone who can help me modify this program or give me ideas

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

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            of.ShowDialog();
            textBox1.Text = of.FileName;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            StreamReader sr = new StreamReader(textBox1.Text);
            richTextBox1.Text = sr.ReadToEnd();
            sr.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            StreamWriter sw = new StreamWriter(textBox1.Text, true);
            sw.WriteLine(textBox2.Text);
            sw.Close();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            int index = 0; string temp = richTextBox1.Text; richTextBox1.Text = ""; richTextBox1.Text = temp;
            while (index < richTextBox1.Text.LastIndexOf(textBox3.Text))
            {
                richTextBox1.Find(textBox3.Text, index, richTextBox1.TextLength, RichTextBoxFinds.None);
                richTextBox1.SelectionBackColor = Color.Yellow;
                index = richTextBox1.Text.IndexOf(textBox3.Text, index) + index;
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:15:48+00:00Added an answer on June 2, 2026 at 5:15 am

    Searching in .doc file will be a little hard, since doc files contain markup in order to give you the ability to decorate your text (with different font, bold, italic, margins, etc.). There are third party library and products that might help you with this one. Txt files on the other hand are plain text, that’s why you don’t have problems with this one.

    In order to implement the validation, you can use the File static class and check the extension of the file and decide what to do next. You can also use the System.IO.Path.GetExtension method which takes the file name and gives you the extension.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a simple Java program with below directory structure: MyProject (A project in
Below is a simple program that creates a thread. I hope I am missing
The code pasted below is a simple JSF program, with an idea of having
Below, I have a simple program which uses the CImg library (http://cimg.sourceforge.net/) which iterates
Below I have written a sample program that I have written to learn about
below i have a code that runs in most of my simple programs ..
I have a simple MFC program which displays the progressbar..I used the below code
I have a very simple VB.net Windows Service written using VS.net 2008. The program
Running the really simple program below I'd expect 'FILTER REACHED' to execute when I
I have a simple javascript program that's acting a little funny. When I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.