Hi all. Question about directories i have to send this file to my teacher via email then he will install the app. My problem is if i give him this code ( which work fine on my computer) i have no way of know what drive he will install this on which will stop the program from run how can i get around this.
const string FILENAME = @"C:\Users\michael\Documents\data.txt";
My Code:
namespace WriteFriendRecords
{
public partial class Form1 : Form
{
const string Record = ",";
const string FILENAME = @"C:\Users\michael\Documents\data.txt";
string firstName, lastName, birthMonth;
int phoneNoArea, phoneNo, birthDay;
static FileStream outFile = new FileStream(FILENAME, FileMode.Create, FileAccess.Write);
StreamWriter Writer = new StreamWriter(outFile);
public Form1()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
firstName = txtFirstName.Text;
lastName = txtLastName.Text;
phoneNoArea = Convert.ToInt32(txtAreaCode.Text);
phoneNo = Convert.ToInt32(txtPhoneNumber.Text);
birthMonth = txtBirthMonth.Text;
birthDay = Convert.ToInt32(txtDateOfBirth.Text);
Writer.WriteLine(firstName + Record + lastName + Record + phoneNoArea + Record + phoneNo + Record + birthMonth + Record + birthDay + Record);
// Clear the Text Boxes
txtFirstName.Clear();
txtLastName.Clear();
txtAreaCode.Clear();
txtPhoneNumber.Clear();
txtBirthMonth.Clear();
txtDateOfBirth.Clear();
MessageBox.Show("File Saved");
}
private void btnExit_Click(object sender, EventArgs e)
{
Writer.Close();
outFile.Close();
if (Disposing && (components != null))
{
components.Dispose();
}
base.Dispose(Disposing);
Application.Exit();
}
}
}