Hi,
I'm trying to programmatically download a word document from LF repository but It's getting corrupted / 'Word found unreadable content' message.
Here is my code snippet
public File GetFileInfo(int id) {
DocumentInfo file = Document.GetDocumentInfo(id, this.Session);
return new File() {
Name = file.Name,
Extension = file.Extension,
Created = file.CreationTime,
CreatedBy = file.Creator,
Modified = file.LastModifiedTime,
ModifiedBy = null,
Size = file.ElecDocumentSize
};
}
using (var Service = Import.PublishingService) {
var fileinfo = Service.GetFileInfo(identifier);
// upload file //
var totalsize = fileinfo.Size;
var offset = 0;
string tempfilename = Path.GetFileNameWithoutExtension(filename) + " " + Guid.NewGuid().ToString() + Path.GetExtension(filename);
tempfilelocation = System.Environment.GetEnvironmentVariable("eScribePath") + "\\Temp\\" + tempfilename;
using (FileStream fs = new FileStream(tempfilelocation, FileMode.Create, FileAccess.ReadWrite)) {
while (offset < totalsize) {
int count = 262144;
byte[] buffer = Service.GetFileBytes(identifier, offset, count);
count = buffer.Length;
fs.Write(buffer, 0, count);
offset += count;
}
}
Any thoughts on why is this happening?