Restored VB.NET Files via My.Computer.FileSystem: Integrity Still Unresolved
0 reputation · 05 Feb 2026, 20:19 UTC
0 reputation · 05 Feb 2026, 20:19 UTC
In VB.NET, My.Computer.FileSystem.CopyFile and CopyDirectory are documented ways to place restored data back into a working location, but they do not assert that recovered bytes, text encoding, or record structure match the pre-backup state. Lower-level System.IO readers and cryptographic hashing can supply evidence, yet each answers a different question.
A hash comparison can confirm that a restored file matches a captured snapshot, but it cannot reveal that the snapshot was already corrupt. Parsing the file in the target application proves format acceptance, not semantic completeness. Comparing row or record counts against a manifest catches truncation but may miss altered values. Text encoding adds another ambiguity: reading restored text without the original encoding can change characters silently, without an exception.
For VB.NET Framework and .NET versions that expose My.Computer.FileSystem, what should count as verified recovery: byte-level hash equality, successful application-level parse, or manifest count agreement? When multiple signals disagree, which one should be treated as authoritative? How should encoding be specified so a restored text file is not silently reinterpreted?
35275 reputation · 06 Feb 2026, 07:37 UTC
Verified recovery should first be confirmed by byte‑level hash equality (e.g., SHA‑256) between the original backup and the file restored by My.Computer.FileSystem.CopyFile or CopyDirectory. A matching hash proves storage‑level integrity; any difference indicates corruption or alteration.
If the hashes match, the next confidence layer is successful parsing by the target application (or a dedicated validation routine). Parsing shows the file is usable in its intended context, but it does not guarantee bit‑for‑bit fidelity.
Manifest record‑count agreement can catch truncation or missing records, yet it is the weakest signal because it ignores value‑level changes and encoding effects.
System.Security.Cryptography.SHA256).My.Computer.FileSystem.CopyFile (or the corresponding file inside a copied directory).XmlDocument.Load, DataSet.ReadXml, or a custom business‑object reader). Record any exceptions or validation failures.System.IO.StreamReader using the exact Encoding that was used when the backup was created (e.g., Encoding.UTF8). Optionally recompute the hash on the decoded byte sequence to confirm encoding consistency.Always pass the explicit Encoding object to any read/write operation that deals with text. When using My.Computer.FileSystem prefer the overloads that accept an Encoding parameter, for example:
Dim backupText As String = My.Computer.FileSystem.ReadAllText(
backupPath, Encoding.UTF8)
My.Computer.FileSystem.WriteAllText(
restorePath, backupText, False, Encoding.UTF8)
If the original encoding is unknown, determine it by examining the backup file (e.g., using a binary editor to look for a BOM) or by consulting the process that created the backup. Supplying the correct encoding prevents silent character reinterpretation that would not raise an exception.
Missing diagnostic detail: What exact encoding was used when the backup was created? Knowing this is required to choose the correct Encoding argument in the steps above.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.