c# - opening binary files from SQL using LINQ -


i saving word/excel/pdf/img files in sql using binary , able save files binary.

var filesize = fileupload1.postedfile.contentlength; var documentbinary = new byte[filesize]; var u = new udocument                 {                     docname = filename.tostring(cultureinfo.invariantculture),                     type = documenttype.tostring(cultureinfo.invariantculture),                     docdata = documentbinary                 };                 u.docid = ++count;                 sd.udocuments.insertonsubmit(u);                 sd.submitchanges(); 

now, trying open binary document type, , opening gridview displaying stored files.

enter image description here

now, in gridview selectedindexchange event, able document id, document name, me open file,but unclear how grab binary data documentid, pk, , how write file out. here method trying make work:

protected void gridview1_selectedindexchanged(object sender, eventargs e)     {         int docid = convert.toint16(gridview1.selectedrow.cells[1].text);         string name = gridview1.selectedrow.cells[2].text;         response.clear();         response.contenttype = "application/octet-stream";         response.addheader("content-disposition", "attachment;filename=" + name);         response.binarywrite(getdata(docid)); // unclear on how use method,          response.flush();     } 

where, in getdata(int id) method, trying use linq correct binary data through unique docid this:

var data = in sd.udocuments             a.docid == id             select a.docdata 

but not sure return type use in method.

any or pointers great.

the return type of getdata should same type of docdata property, i.e. byte[].


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -