4

I'm trying to use the rest API for uploading a WORD document (*.doc) to docusign with the below code. But Exception thrown - UNABLE_TO_LOAD_DOCUMENT, Document corrupt. If I use the same document to upload directly from docusign website using my Dev Account it uploads correctly without any error. Can anyone help me to find out what's wrong with the below code. (The below code works fine for a .PDF format file)

byte[] fileBytes = File.ReadAllBytes(pathOfTheWordDocFile);
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";

// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = Path.GetFileName(strPath);
doc.DocumentId = "1";

envDef.Documents = new List<DocuSignModel.Document>();
envDef.Documents.Add(doc);
Pramod
  • 195
  • 1
  • 9

1 Answers1

6

By default the document content-type is set to application/pdf. To use a different mime-type you simply need to set the file extension using

doc.FileExtension = "docx";

Try adding that line to your code and it should work, like this:

byte[] fileBytes = File.ReadAllBytes(pathOfTheWordDocFile);
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";

// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = Path.GetFileName(strPath);
doc.DocumentId = "1";
doc.FileExtension = "docx";

envDef.Documents = new List<DocuSignModel.Document>();
envDef.Documents.Add(doc);
Ergin
  • 9,254
  • 1
  • 19
  • 28
  • Thank You. I did include two lines now. 1. FileExtension as suggested and add the Header as "Content-Type":application/vnd.openxmlformats-officedocument.wordprocessingml.document (this one is to state the content type to be of type docx) – Pramod Apr 13 '16 at 00:24