Q:

WriteFile failure modes

What can happen to a file that is being written to over a network share when the network connection "fails?"  I imagine multiple things can happen.
The reason I ask is because a program that I wrote appeared to corrupt a file in a way that I have never seen before.  Actually, I have never received a report of my program creating a corrupt file before, and I feel confident if it corrupted a file I would hear about it.  The code that that actually generated the corrupt file is actually Microsoft code.  The file is created when the save function is called on the IXMLDOMDocument2 interface from the MSXML4.0 COM component.  The function created an invalid XML document.  The last 5452 bytes of a 33789 byte file was filled with NULLs (0x00).  I'm trying to understand what happened.

A:

The short answer is that the file can be corrupted (as you've already found).
From there, nearly the only interesting question is how you prevent that from happening again. The typical way is to write the data to a temporary file, then after it's written rename it to the correct name. If the network connection dies in the middle of this, you won't have the correct file name. To recover, you delete any temporary files, and restart the operation from the beginning.

