asp.net mvc - How can i display the file name in the Edit View? File name is stored in the images Folder and also in database -
view is
@html.textboxfor(model => model.choosefile, "", new { @class = "span12", placeholder = "choose file",type="file"})
when edit need file name picked , stored in database. image stored in folder image.
i need give download option same.
please me.
you have few options
if file size small, read bytes db , send file result mbc controller
if file large, try streaming.
you can try this
public filecontentresult getfile(int id) { sqldatareader rdr; byte[] filecontent = null; string mimetype = "";string filename = ""; const string connect = @"server=.\sqlexpress;database=filetest;trusted_connection=true;"; using (var conn = new sqlconnection(connect)) { var qry = "select filecontent, mimetype, filename filestore id = @id"; var cmd = new sqlcommand(qry, conn); cmd.parameters.addwithvalue("@id", id); conn.open(); rdr = cmd.executereader(); if (rdr.hasrows) { rdr.read(); filecontent = (byte[])rdr["filecontent"]; mimetype = rdr["mimetype"].tostring(); filename = rdr["filename"].tostring(); } } return file(filecontent, mimetype, filename); }
Comments
Post a Comment