asp.net - How to set MIME type for uploaded file? -
i wrote code upload file database using asp.net , c# . // part binary data , file name , mime type
string filename = path.getfilename(uploadcontract.filename); if (filename != string.empty) { string conttype = uploadcontract.postedfile.contenttype; stream str = uploadcontract.postedfile.inputstream; binaryreader br = new binaryreader(str); byte[] size = br.readbytes((int)str.length); return size; } else { // } after saving file in database name , mime type . tried download same file code
sqlcommand selectcmd = new sqlcommand(); sqlconn = new sqlconnection((string)viewstate["connstr"]); selectcmd.commandtext = @"select tbl_files_filename,tbl_files_filecontent,tbl_files_filemime tbl_files seq=@sq"; selectcmd.connection = sqlconn; selectcmd.parameters.addwithvalue("sq", convert.toint64(request.querystring["id"])); selectcmd.commandtype = commandtype.text; sda.selectcommand = selectcmd; int itemin = sda.fill(ds, "downfile"); sqlconn.close(); if (itemin != 0) { byte[] byt = (byte[])ds.tables["downfile"].rows[0]["tbl_files_filecontent"]; httpcontext.current.response.clear(); httpcontext.current.response.contenttype = ds.tables["downfile"].rows[0]["tbl_files_filemime"].tostring(); httpcontext.current.response.addheader("content-disposition", "attachment;filename=" + ds.tables["downfile"].rows[0]["tbl_files_filename"].tostring()); httpcontext.current.response.charset = ""; httpcontext.current.response.cache.setcacheability(httpcacheability.nocache); httpcontext.current.response.binarywrite(byt); httpcontext.current.applicationinstance.completerequest(); } but faced following problem
excel found unreadable content in "test.xlsx".do want recover contents of workbook? if trust source of workbook, click yes.
it there problem type of file
Comments
Post a Comment