entity framework - Excel File download through web api. Getting corrupt -
i trying download excel file through web api (using entity framework). download working getting error dialog file corrupt when trying open file.
web api code below:
public httpresponsemessage getvalue(int id, string name) { memorystream stream; try { using (datacontext db = new datacontext()) { dynamic fileobj = (from c in db.filelist c.id == idc).tolist(); stream = new memorystream(fileobj(0).file); httpresponsemessage result = new httpresponsemessage(httpstatuscode.ok); result.content = new streamcontent(stream); result.content.headers.contenttype = new mediatypeheadervalue(fileobj(0).filecontenttype); result.content.headers.contentdisposition = new contentdispositionheadervalue("attachment") { filename = name }; return result; } } catch (exception ex) { return request.createresponse(httpstatuscode.internalservererror); } }
it opens file 2 error dialog , following message.
excel completed file level validation , repair. parts of workbook may have been repaired or discarded
Comments
Post a Comment