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;
builder.Writeln("New Header That We Inserted");
doc.BuiltInDocumentProperties.Title = "";
doc.BuiltInDocumentProperties.Subject = "";
doc.BuiltInDocumentProperties.Author = "";
doc.BuiltInDocumentProperties.Manager = "";
doc.BuiltInDocumentProperties.Company = "Our Company Name";
doc.BuiltInDocumentProperties.Category = "";
doc.BuiltInDocumentProperties.Keywords = "Law School Document";
doc.BuiltInDocumentProperties.Comments = "";
doc.BuiltInDocumentProperties.LastSavedBy = "Our Company Name";
doc.Save(OurOtherFolder + DocumentName);
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."