IFormatter serializer; FileStream subFile; CSub newSub; try { if (File.Exists("Submarines.bin")) { lstSub.Items.Clear(); serializer = new BinaryFormatter(); subFile = new FileStream("Submarines.bin", FileMode.Open, FileAccess.Read); long fileLength = subFile.Length; while (subFile.Position < fileLength) { newSub = new CSub(); newSub = serializer.Deserialize(subFile) as CSub; lstSub.Items.Add(newSub); } subFile.Close(); UC.MB("Submarines Loaded", lstSub.Items.Count + " submarine records were successfully loaded from the file Submarines.bin"); } else { UC.MB("File not found", "Could not find the file Submarines.bin"); } } catch (Exception ex) { UC.MB("mnuiLoadSub_Click", ex.Message); } finally { serializer = null; subFile = null; newSub = null; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)