c# - LINQ doesn't provide a byte[] data type for storing files -
i'm trying store file in sql server database , using asp.net mvc 3 linq to sql in c#. when try set data type of column byte[] says invalid data type. using vrabinary(max) data type instead seems logical thing do.
the goal store pdf files in database user has elected upload using http file uploader. error occurs during assignment of linq member variable refers column file stored.
error 3 cannot implicitly convert type 'system.web.httppostedfilebase' 'system.data.linq.binary' c:\users\aaron patten\documents\visual studio 2010\projects\myapp\myapp\controllers\mycontroller.cs 66 31 myapp
i haven't found in way of other people encountering problem, think there must i'm missing elementary post.
my controller:
public actionresult uploadpdf() { list<viewdatauploadfilesresult> r = new list<viewdatauploadfilesresult>(); httppostedfilebase hpf;// = request.files[file] httppostedfilebase; foreach (string file in request.files) { hpf = request.files[file] httppostedfilebase; if (hpf.contentlength == 0) continue; string savedfilename = path.combine(appdomain.currentdomain.basedirectory, "images\\" + path.getfilename(hpf.filename)); hpf.saveas(savedfilename); r.add(new viewdatauploadfilesresult() { name = savedfilename, length = hpf.contentlength }); } myapp.models.myappdatacontext db = new myapp.models.myappdatacontext(); myapp.models.pdffile mypdffile = new myapp.models.pdffile(); mypdffile.content = hpf; db.questions.insertonsubmit(mypdffile); db.submitchanges(); return view("uploadpdf", r); }
what's proper way of going this?
p.s.: how display pdf embedded object without saving server?
d.a.p.
the error message tells what's wrong... setting content=hpf. hpf httppostedfilebase first needs converted byte[]. reading byte[] out of hpf's stream.
mypdffile.content = new binaryreader(hpf.inputstream).readbytes(hpf.inputstream.length)
Comments
Post a Comment