المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Using Text Files [modified]



C# Programming
08-31-2009, 06:49 AM
Hello. I'm having a little problem about text files. When i'm using it, it doesn't append the string into the file. I already specified the path and set the bool append into true.

Here is my code to get a clearer view:


The main program:


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;

namespace VehicleRegistration
{
class Program
{
public static UserRegistration userReg = new UserRegistration();
public static StreamWriter txtNames;
public static StreamWriter txtPlateNum;
public static StreamWriter txtType;
public static StreamWriter txtYear;

static void Main(string[] args)
{
int totalDimension = 0;
string enteredName = "", enteredYear = "", enteredType = "", enteredPlate = "";

Registration(ref totalDimension, ref enteredName, ref enteredPlate, ref enteredYear, ref enteredType);

Console.Read();
}

public static void MainMenu(ref int mainMenu)
{

Console.WriteLine("VEHICLE REGISTRATION\n");

Console.WriteLine("MAIN MENU:\n");

Console.WriteLine("[1] - Vehicle Registration");
Console.WriteLine("[2] - Sort Database");
Console.WriteLine("[3] - Search Database");
Console.WriteLine("[4] - Exit\n");

Console.Write("Enter your choice: ");
mainMenu = Console.Read();

}

public static void Registration(ref int dim, ref string name, ref string plate, ref string year, ref string type)
{
string numDimension;
try
{
txtNames = new StreamWriter("E:\\IT111P\\Case Problem\\Vehicle Registration\\VehicleRegistration\\VehicleRegistration\\bin\\Debug\\names.txt", true);
txtPlateNum = new StreamWriter("E:\\IT111P\\Case Problem\\Vehicle Registration\\VehicleRegistration\\VehicleRegistration\\bin\\Debug\\platenum.txt", true);
txtType = new StreamWriter("E:\\IT111P\\Case Problem\\Vehicle Registration\\VehicleRegistration\\VehicleRegistration\\bin\\Debug\\type.txt", true);
txtYear = new StreamWriter("E:\\IT111P\\Case Problem\\Vehicle Registration\\VehicleRegistration\\VehicleRegistration\\bin\\Debug\\txtYear.txt", true);
}
catch (DirectoryNotFoundException)
{
}
Console.Write("Enter the total number of vehicles to be registered: ");
numDimension = Console.ReadLine();
dim = Convert.ToInt32(numDimension);
userReg.Dimension = dim;

Console.Write("\n");

for (int a = 0; a < userReg.Dimension; a++)
{
try
{
Console.Write("Enter the Last name of the owner: ");
name = Console.ReadLine();
userReg.NameOfOwner = name;
txtNames.Write(name);

Console.Write("Enter the plate number of the vehicle: ");
plate = Console.ReadLine();
userReg.PlateNumber = plate;
txtPlateNum.WriteLine(plate);

Console.Write("Enter the type of vehicle: ");
type = Console.ReadLine();
userReg.TypeOfVehicle = type;
txtType.Write(type);

Console.Write("Enter year registered: ");
year = Console.ReadLine();
userReg.YearReg = year;
txtYear.Write(year);
}
catch (System.IO.IOException)
{
}

Console.Write("\n");
}


}



}
}



modified on Sunday, August 30, 2009 10:42 PM