title: How to fix error "unable to open the document, file appears to be corrupt" while opening a document written using react-native fs?
body: <p>I was trying to write data to a document file using <code>react-native-fs</code> and then mail that document to another user using <code>react-native-mail</code> package. </p>
  
  <p>I've successfully implemented that except one thing. When I try to open the document it is showing "<strong>unable to open the document, file appears to be corrupt</strong>". But when I try to send this in txt format I can open the file and view its content. Why I'm not able to reproduce the same in case of doc format. Below is my code.</p>
  
  <pre><code>if (
          permRes["android.permission.READ_EXTERNAL_STORAGE"] ===
            PermissionsAndroid.RESULTS.GRANTED &amp;&amp;
          permRes["android.permission.WRITE_EXTERNAL_STORAGE"] ===
            PermissionsAndroid.RESULTS.GRANTED
        ) {
          if (data !== null) {
            data.map(item =&gt; {
              var path = RNFS.ExternalStorageDirectoryPath + "/test.doc";
              console.log("pathpath", path);
              RNFS.writeFile(
                path,
                "Project Details\n" +
                  "\nProject name: " +
                  item.project_name +
                  "\nProject Description: " +
                  item.project_description +
                  "\nClient name: " +
                  item.client_name +
                  "\nCompany: " +
                  item.company +
                  "\nPhone number: " +
                  item.phone_number +
                  "\nEmail: " +
                  item.email,
                "utf8"
              )
                .then(success =&gt; {
                  console.log("FILE WRITTEN");
                  Mailer.mail(
                    {
                      subject:
                        Strings.string_rem + " :" + Strings.string_projectDetails,
                      recipients: ["vinaynarayankutty@gmail.com"],
                      body: "&lt;b&gt;This is a test document&lt;/b&gt;",
                      isHTML: true,
                      attachment: {
                        path: RNFS.ExternalStorageDirectoryPath + "/test.doc",
                        type: "doc",
                        name: "Project details"
                      }
                    },
                    (error, event) =&gt; {
                      Alert.alert(
                        error,
                        event,
                        [
                          {
                            text: "Ok",
                            onPress: () =&gt; console.log("OK: Email Error Response")
                          },
                          {
                            text: "Cancel",
                            onPress: () =&gt;
                              console.log("CANCEL: Email Error Response")
                          }
                        ],
                        { cancelable: true }
                      );
                    }
                  );
                })
                .catch(err =&gt; {
                  console.log(err.message);
                  alert(err.message);
                });
            });
          }
        }
  </code></pre>