Cis 170 Week 7 Lab Programming Assignments

01 August, 2024 | 1 Min Read

// —————————————————————

// Programming Assignment: LAB7

//

// Date Written: 10-16-2012

// Purpose: Contact Manager

// —————————————————————

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.IO; using System.Windows.Forms;

namespace Lab7

{

public partial class Form1 : Form

{

    public Form1()

    {

        InitializeComponent();

    }

    private void cmdAdd\_Click(object sender, EventArgs e)         {

        string fileName = "C:\\\CIS\\\Contacts.txt";

        string name, eMail;             StreamWriter outFile;             if (!File.Exists(fileName))

        {

            File.Create(fileName);

        } try                 {

                outFile = new StreamWriter(fileName, true) ;                     name = txtName.Text;                     eMail = txtEMail.Text;                     outFile.WriteLine(name);                     outFile.WriteLine(eMail);                     outFile.Close();

            }

            catch (DirectoryNotFoundException exc)

            {

                MessageBox.Show(exc.Message);

            }

            catch (System.IO.IOException exc)

            {

                MessageBox.Show(exc.Message);                 }

        }

    }

}

Related posts