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

  • Home
  • SEARCH
  • 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 8660969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:23:03+00:00 2026-06-12T16:23:03+00:00

I have this button click event: private void button6_Click(object sender, EventArgs e) { if

  • 0

I have this button click event:

private void button6_Click(object sender, EventArgs e)
{
    if (File.Exists(@"d:\Keywords.txt"))
    {
        Dictionary<string,string> test = new Dictionary<string,string>();
        string value_of_each_key;
        string key_of_each_line;
        string line;
        int index;
        sr = new StreamReader(@"d:\Keywords.txt");
        while (null != (line = sr.ReadLine()))
        {
             index = line.IndexOf(",");
             key_of_each_line = line.Substring(0, index);
             value_of_each_key = line.Substring(index + 1);
             test.Add(key_of_each_line, value_of_each_key);
        }
        sr.Close();
     }

     using (var w = new StreamWriter(@"D:\Keywords.txt"))
     {
         crawlLocaly1 = new CrawlLocaly();
         crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
         DialogResult dr = crawlLocaly1.ShowDialog(this);
         if (dr == DialogResult.OK)
         {
             if (LocalyKeyWords.ContainsKey(mainUrl))
             {
                 LocalyKeyWords[mainUrl].Clear();
                 //probably you could skip this part and create new List everytime
                 LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
             }
             else
             {
                 LocalyKeyWords[mainUrl] = new List<string>();
                 LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
             }
             foreach (KeyValuePair<string, List<string>> kvp in LocalyKeyWords)
             {
                 w.WriteLine(kvp.Key + "," + string.Join(",", kvp.Value));
             }
         }
     }  
 }

The reading of the text file is working good ( did it for a test for now and its working good ).
Thep roblem is that each time i click the button it will also create a new text file and what i want is that when i click the button the text file will be ready to add a new text to him and not ot create each time a new one.

How can i solve that ?

  • 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-12T16:23:04+00:00Added an answer on June 12, 2026 at 4:23 pm

    It sounds like you just want to change this:

    new StreamWriter(@"D:\Keywords.txt")
    

    To this:

    new StreamWriter(@"D:\Keywords.txt", true)
    

    That will use the overload of the StreamWriter constructor which has a second parameter controlling overwrite/append behaviour.

    Alternatively, and more readably, use File.AppendText:

    File.AppendText(@"D:\Keywords.txt")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button click event for continue: private void button3_Click(object sender, EventArgs e)
I have this code: 001 private void uiButton1_Click(object sender, EventArgs e) 002 { 003
In maine, on my button click event handler I do: private void addIconButton_Click(object sender,
I have to call a function on a button click event like this private
I have the following event handler: private void rtb_MouseDown(object sender, MouseEventArgs e) { if
I have a button click event handler with the following pseudo code: private void
I have an NIB file with a button. When I click this button, the
I have other-window.xaml file and trying to open this from window.xaml on button click.
I have this code first the constructor and button click event: using System.Text; using
I have the following code for a button click event. This event should open

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.