c# - "Unable to read file" error in IE when "Open" html file with Excel, but not when "Save" first -
this first question on forum, please forgive newbie errors.
i have .net code, within web application, creates html table dynamically info pulled database, streams user's web browser opened in excel. works fine in chrome. works in ie 11 long user, after clicking "download" link, chooses "save" alternative (saving file before opening it), rather "open" alternative - tries read file beingness streamed client. in ie 11, if take "open" option, warning excel format of file (because html file - same thing happens if save first, , acceptable), when click "yes" open anyway, see "unable read file." error message.
in 1 case, able prepare problem replacing instances if "&" in info word "and". however, in other cases, cannot determine particular info value might causing issue. , again, file opens fine long user saves first. (in fact, works fine when click "open" instead of "save" in development environment - not when test server code deployed.)
so, looking either way remove/replace problematic info displayed within "td" elements of html table, or, improve yet, way create "open" alternative have same result "save" option. again, html table content opens fine long file saved first.
the html table generated c# class, page streams file in vb.net. don't think c# code useful (but can post in part if thinks be), here vb code in relevant part:
class="lang-vb prettyprint-override">response.clear() response.clearcontent() response.clearheaders() dim htmltable string '[snip - populate htmltable info database] dim filename string = "whatever.xls" response.buffer = false response.contenttype = "application/vnd.ms-excel" response.appendheader("content-disposition", "attachment; filename=""" & filename & """") response.addheader("content-length", asciiencoding.ascii.getbytecount(htmltable).tostring()) using ms new memorystream(encoding.ascii.getbytes(htmltable)) ms.writeto(response.outputstream) response.flush() end using update: may have fixed issue "cleansing" info (c#) code below, still don't understand why file ever has saved first, have made unnecessary. reply welcome.
private string getdatarow(datarow dr, list<datacolumninfo> fieldinfolist) { var sb = new stringbuilder("<tr valign='top' align='left'>"); // see http://stackoverflow.com/questions/4619909/format-html-table-cell-so-that-excel-formats-as-text var forceexceltext = "mso-number-format:\"\\@'\""; fieldinfolist.foreach(c => { var content = dr[c.fieldname].tostring() .replace("&", "and") .replace("<", "") .replace(">", ""); // replace non-asccii content = encoding.ascii.getstring(encoding.ascii.getbytes(dr[c.fieldname].tostring())); sb.append("<td style='" + forceexceltext + "'>" + content + "</td>"); }); sb.append("</tr>"); homecoming sb.tostring(); } new update - above code did not prepare problem. still error in cases when take "open" alternative instead of "save" first. if save first, fine.
c# html vb.net excel internet-explorer
No comments:
Post a Comment