Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Form1_Load(object sender, EventArgs e)
- {
- // Check if directory exists
- if (Directory.Exists(@"C:UsersrsDesktopTest)"))
- {
- // Do nothing
- }
- else
- {
- Directory.CreateDirectory(@"C:UsersrsDesktopTest");
- }
- if (File.Exists(@"C:UsersrsDesktopTesttest.txt"))
- {
- // Do nothing
- }
- else
- {
- File.Create(@"C:UsersrsDesktopTesttest.txt");
- }
- StreamReader sr = new StreamReader(@"C:UsersrsDesktopTesttest.txt");
- while (sr.Peek() >= 0)
- {
- combox_Name2.Items.Add(sr.ReadLine());
- }
- sr.Close();
- }
- private void btn_Save_Click(object sender, EventArgs e)
- {
- StreamWriter writer = new StreamWriter(@"C:UsersrsDesktopTesttest.txt", true);
- try
- {
- Process.Start(combox_Name2.Text, txt_Name.Text);
- if (combox_Name2.Items.Contains(txt_Name.Text))
- {
- // Do nothing
- }
- else
- {
- writer.WriteLine(combox_Name2.Text);
- writer.Flush();
- writer.Dispose();
- combox_Name2.Items.Add(txt_Name.Text);
- }
- }
- catch
- {
- MessageBox.Show("The file '" + txt_Name.Text + "' could not be located", "File could not be located");
- }
- }
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Diagnostics;
- namespace FileHandling
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- // Check if directory exists
- if (Directory.Exists(@"C:UsersrsDesktopTest)"))
- {
- // Do nothing
- }
- else
- {
- Directory.CreateDirectory(@"C:UsersrsDesktopTest");
- }
- if (File.Exists(@"C:UsersrsDesktopTesttest.txt"))
- {
- // Do nothing
- }
- else
- {
- File.Create(@"C:UsersrsDesktopTesttest.txt");
- }
- using (StreamReader writer = new StreamReader(@"C:UsersrsDesktopTesttest.txt"))
- {
- while (writer.Peek() >= 0)
- {
- combox_Name2.Items.Add(writer.ReadLine());
- }
- writer.Close();
- }
- }
- private void btn_Save_Click(object sender, EventArgs e)
- {
- using (StreamWriter writer = new StreamWriter(@"C:UsersrsDesktopTesttest.txt", true))
- {
- try
- {
- if (combox_Name2.Items.Contains(txt_Name.Text))
- {
- MessageBox.Show("The task '" + txt_Name.Text + "' already exist in list", "Task already exists");
- }
- else
- {
- combox_Name2.Items.Add(txt_Name.Text);
- writer.WriteLine(txt_Name.Text);
- writer.Flush();
- writer.Dispose();
- }
- }
- catch
- {
- MessageBox.Show("The file '" + txt_Name.Text + "' could not be located", "File could not be located");
- }
- }
- }
- }
- }
- using(IDisposable object goes here)
- {
- // Do something.
- }
- using(StreamWriter writer = new StreamWriter(@"C:UsersrsDesktopTesttest.txt", true))
- {
- // do your thing here.
- }
- StreamWriter writer = new StreamWriter(@"C:UsersrsDesktopTesttest.txt", true);
- try
- {
- // do your thing here.
- }
- finally
- {
- writer.Dispose();
- }
- combox_Name2.Items.Clear();
- if (File.Exists(@"C:UsersrsDesktopTesttest.txt"))
- {
- using(StreamReader sr = new StreamReader(@"C:UsersrsDesktopTesttest.txt"))
- {
- while (sr.Peek() >= 0)
- {
- combox_Name2.Items.Add(sr.ReadLine());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement