0

I have written a script which creates a new txt file into the document library using Javascript. When I change the file extension to docx, it still creates but I'm unable to view the file.. It gives me an error that the file is corrupted.

Can someone tell me what is going on here?

  • Is there any content in the file or is it blank?if its blank, there needs to be some content in it. – Eric Alexander Feb 13 '15 at 15:00
  • There is content in it. The txt file opens with no error. Only when it comes to docx, it gives me an error. – Keerthi Feb 13 '15 at 15:01
  • I have used the code given in this example - msdn.microsoft.com/en-us/library/… – Keerthi Feb 13 '15 at 15:03
  • Can you please share your code that creates a text file in a document library using JavaScript? I'm trying to accomplish the same thing. – IMTheNachoMan Nov 5 '15 at 13:02
3

The code you are using is used to create a simple text file. But, a docx file is not a simple text file. It is a series of XML files inside a zip container with a .docx extension, also known as OpenXML. You need to write the code to create a file in the OpenXML or find and use a library that supports JavaScript.

Note that if you create a .txt file, change the extension to .docx and open in Word on your local machine you will receive the same corruption error. Similarly, if you create a docx file using Word, change the extension to .zip and open it you will see all the supporting .xml files that make up the "text" document.

Here are some references: http://en.wikipedia.org/wiki/Office_Open_XML http://openxmldeveloper.org/wiki/w/wiki/open-xml-sdk-for-javascript.aspx https://code.msdn.microsoft.com/Apps-for-Office-Loading-7a453236

  • Thanks Erik. I there a simple example to create a docx file using Javascript? – Keerthi Feb 13 '15 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.