Setting header and document properties and then saving results in corrupted Word document.

Last post 02-12-2012, 12:29 PM by awais.hafeez. 1 replies.
Sort Posts: Previous Next
  •  02-10-2012, 12:07 PM 360811

    Setting header and document properties and then saving results in corrupted Word document. .NET

    Attachment: Present (inaccessible)

    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."

     
  •  02-12-2012, 12:29 PM 360890 in reply to 360811

    Re: Setting header and document properties and then saving results in corrupted Word document.

    Hi Paul,

    Thanks for your inquiry.

    I was unable to reproduce this issue on my side. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v11.0.0 and let us know your findings then.

    Best Regards,

    Awais Hafeez
    Support Developer
    Aspose Sialkot Team
    Aspose - Your File Format Experts

    Keep in touch! We're on Twitter and Facebook
     
View as RSS news feed in XML