c# - Converting a byte[]-Array to ANSI -
i trying convert byte[] blob in mssql database windows-1252 ansi format using c# , microsoft lightswitch, , return results file download.
this thought should work...
i'm creating string with
system.text.encoding v_unicode = system.text.encoding.unicode; system.text.encoding v_ansi_windows_1252 = system.text.encoding.getencoding(1252); string v_content_1252 = v_ansi_windows_1252.getstring(system.text.encoding.convert(v_unicode, v_ansi_windows_1252, v_unicode.getbytes(v_content))); byte[] ansiarray = v_ansi_windows_1252.getbytes(v_content_1252);
and write in database. when try retrieve with
int v_fileid = int32.parse(context.request.querystring["p_fileid"]); datatablename v_fexpd = servercontext.dataworkspace.applicationdata.datatablename_singleordefault(v_fileid); memorystream memstream = new memorystream(v_fexpd.inhalt); string v_content= system.text.encoding.getencoding(1252).getstring(v_fexpd.content); context.response.clear(); context.response.contenttype = "text/csv"; context.response.addheader("content-disposition", "attachment; filename=" + v_fexpd.filename); context.response.write( v_content ); context.response.end();
... returns unicode. doing wrong?
this having similar problem. answer go way on stream... did following:
// create temporary file, delete if exists string myfile = path.gettemppath() + v_fexpd.dateiname; if (file.exists(myfile)) { file.delete(myfile); } using (textwriter tw = new streamwriter(myfile.tostring(), true, system.text.encoding.getencoding(1252))) tw.writeline(v_inhalt); context.response.clear(); context.response.addheader("content-disposition", "attachment; filename=" + v_fexpd.dateiname); context.response.addheader("content-type", "text/csv; charset=windows-1252"); // write file - @ point correctly-encoded - // directly output. context.response.writefile(myfile); context.response.end(); // leave no traces file.delete(myfile);
Comments
Post a Comment