I am retrieving a .docx file as a byte array. I am then trying to call the Doc’s read() function with said byte array as the data parameter but I am getting an unrecognized file extension error.
I retrieve the byte array with the following (c#) code:
WebClient testWc = new WebClient();
testWc.Credentials = CredentialCache.DefaultCredentials;
byte[] data = testWc.DownloadData("http://localhost/Lists/incidents/Attachments/1/Testdocnospaces.docx");
IF at this point I output the byte array as a .docx file, my program will correctly allow me to open or save the file. For this reason, I believe the byte array has been retrieved correctly. Here is a sample of what I mean by outputting a .docx file:
Response.ClearHeaders();
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;Filename=test.docx");
Response.BinaryWrite(data);
Response.Flush();
Response.End();
However, if I try to read the byte array into a Doc like so:
Doc doc = new Doc();
XReadOptions xr = new XReadOptions();
xr.ReadModule = ReadModuleType.MSOffice;
doc.Read(data, xr);
My program will error out at the last line of said code, throwing the following: “FileExtension '' was invalid for ReadModuleType.MSOffice.”
The Doc.Read() function seems to be finding an empty string where it would typically be finding the file type. Also, I do have Office 2007 installed on this machine.