How can I save a document as .docx locally using the API?
I got the URL, and managed to do a workaround like this:
Dim documentUri As Uri = New Uri(feed.Entries(0).Content.AbsoluteUri + "&exportFormat=docx&format=docx")
Dim stream As Stream = service.Query(documentUri)
Dim streamReader As StreamReader = New StreamReader(stream)
Dim streamWriter As StreamWriter = New StreamWriter("C:\\download.docx")
Dim line As String = streamReader.ReadLine()
While (line <> Nothing)
streamWriter.WriteLine(line)
line = streamReader.ReadLine()
End While
streamReader.Close()
streamWriter.Flush()
streamWriter.Close()
My file is getting corrupted though. Any ideas on what I’m doing wrong?
And other question: has the support for downloading in doc been removed? I’ve read the documentation some weeks ago, and it was there (as well as in the user interface) but reading again, even though the “doc” option is there, there’s a note saying it will get downloaded as docx. Any way to download it as .doc?
You should read and write it as binary, not as lines.
You will always get a docx when requesting doc or docx. This is a recent change in the API, but it is in alignment with Microsoft’s policy to move away from the older binary formats. If you have older MS Office, you can download the compatibility pack to view docx.