E-mail
Uses recursion. And System.IO
Had a debugging issue in the code, where there was an extra space which caused a –1 to be displayed in Directories found.
The catch block in the class was suppressing the error, so I put in a throw statement in the catch block which stopped the VS debugger, and pointed me to the correct place.
catch (Exception ex)
{
//throw; // great while debugging to get the line number of the exception
return -1;
}
A useful class that writes to a textfile log, then can read back from it. Creates the file if it doesn’t exist. Appends to the file if it does exist.
string pfn = Path.Combine(pathName, fileName);
if (File.Exists(pfn))
sr = new StreamReader(pfn);
buff = sr.ReadToEnd();
sr.Close();
return buff;
sw = new StreamWriter(Path.Combine(pathName, fileName), true);
sw.WriteLine(currentDT.ToShortDateString() + ", " +
currentDT.ToShortTimeString() + ": " +
errorMessage);
sw.WriteLine("-----------------------------");
sw.Close();
Uses frmMain for display logic, and clsRandomAccess for writing and reading data to disk.
In clsRandomAccess there are Property Methods for all fields:
public string FirstName
get
return firstName;
set
if (value.Length > 0) // Do we have a string?
firstName = value;
if (firstName.Length > NAMESIZES) // Too long
firstName = firstName.Substring(0, NAMESIZES); // Trim it.
All methods return a 0 if error, otherwise 1 if success. Uses a binarywriter, and has to calculate the size of each record to know where to read to.
Uses [Serialize] attribute on clsSerial class.
/// <summary>
/// To serialize the contents of the class
/// </summary>
/// <param name="serial"></param>
/// <returns>0 on error, 1 otherwise</returns>
public int SerializeFriend(clsSerial myFriend)
try
BinaryFormatter format = new BinaryFormatter();
FileStream myStream = new FileStream("Test.bin", FileMode.Create);
format.Serialize(myStream, myFriend);
myStream.Close();
string buff = ex.Message;
return 0;
return 1;
Remember Me
a@href@title, strike