Modifying a document and then resaving is somehow corrupting the document. This only happens occasionally, so I guess it is only triggered by documents with certain features or characteristics (unknown at this time).
I have attached a document for you to experiment with. In our code, we open this document and then insert a new header, and then reset all of the document's properties. Then we save the document and move it to a new folder on the web server.
string OurFolder = HostingEnvironment.MapPath("~/tempupload/");
Document doc = new Document(OurFolder + DocumentName);
DocumentBuilderbuilder = new DocumentBuilder(doc);
builder.PageSetup.DifferentFirstPageHeaderFooter = false;
builder.PageSetup.OddAndEvenPagesHeaderFooter = false;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Font.Name = "Arial";
builder.Font.Underline = Underline.Single;
builder.Font.Size = 10;
<br><br>builder.Writeln("New Header That We Inserted");</font></p><p><font size="2" face="Courier New">doc.BuiltInDocumentProperties.Title = "";
<br>doc.BuiltInDocumentProperties.Subject = "";
<br>doc.BuiltInDocumentProperties.Author = "";
<br>doc.BuiltInDocumentProperties.Manager = "";
<br>doc.BuiltInDocumentProperties.Company = "Our Company Name";
doc.BuiltInDocumentProperties.Category = "";
<br>doc.BuiltInDocumentProperties.Keywords = "Law School Document";
doc.BuiltInDocumentProperties.Comments = "";
<br>doc.BuiltInDocumentProperties.LastSavedBy = "Our Company Name";</font></p><p><font size="2" face="Courier New">doc.Save(OurOtherFolder + DocumentName);</font></p><p><font size="4" face="Tahoma">At this point, if you try and open the document with Word, you are unable to open it and get this error: "The file cannot be opened because there are problems with the contents."</font></p>