You must Sign In to post a response.
  • Category: .NET

    Read and write file to docx file.

    Hi,

    I am reading a docx file content with below code

    string filePath = @"D:\Projects\Webapi\Docs\test1.docx";
    using (FileStream fs =File.Open(filePath, FileMode.Open)) {
    content = new byte[fs.Length];
    fs.Read(content, 0, (int)fs.Length);
    }

    now i am creating new file with the content as below
    File.WriteAllBytes(@"D:\Projects\Webapi\Docs\b.docx", content);

    I am able to read and write all these things to new doc.

    Now the problem is i want to break(split) the content which is in byte array.

    when i am split and write to docx file, docx is showing error as invalid content or document is corrupted.

    How to achieve this?

    Regards,
    Naresh.
  • #769815
    I suggest you load the byte array to a Word document, and then split the document into two files.

    Document doc = new Document();
    doc.LoadFromStream(stream, FileFormat.Docx2013);

    Split Word Document by Page Breaks:
    https://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/Document-Operation/How-to-split-a-word-document-by-page-break-in-C.html


  • Sign In to post your comments