c# - Trying to convert an xsl file and an xml file to html and then display that in a WebBrowser object -
so trying convert xml file uses xsl file convert both of html can bind webbrowser object. here have far isnt working:
protected string convertxslandxmltohtml(string xmlsource, string xslsource) { string resultdoc = application.startuppath + @"\result.html"; string htmltopost; try { xpathdocument myxpathdoc = new xpathdocument(xmlsource); xsltransform myxsltrans = new xsltransform(); //load xsl myxsltrans.load(xslsource); //create output stream xmltextwriter mywriter = new xmltextwriter(resultdoc, null); //do actual transform of xml myxsltrans.transform(myxpathdoc, null, mywriter); mywriter.close(); streamreader stream = new streamreader(resultdoc); htmltopost = stream.readtoend(); stream.close(); file.delete(resultdoc); return (htmltopost); } catch (filenotfoundexception fileex) { messagebox.show("file not found: " + fileex.filename, "file not found error", messageboxbuttons.ok, messageboxicon.error); return null; } catch (exception ex) { messagebox.show("general exception: " + ex.message, "exception thrown" , messageboxbuttons.ok, messageboxicon.error); return null; } } this code in function returns htmltopost , returning data bound webbrowser this:
// webreport webbrowser object // htmlstring html passed function // bind html text webbrowser object webreport.navigate("about:blank"); ihtmldocument2 test = (ihtmldocument2)webreport.document.domdocument; test.write(htmlstring); webreport.document.write(string.empty); webreport.documenttext = htmlstring; i know xsltransform has been deprecated examples online use thats why using it.
the error :
a runtime error has occured. wish debug?
line: 177 error: expected ')'
it happens when code tries execute:
ihtmldocument2 test = (ihtmldocument2)webreport.document.domdocument; test.write(htmlstring); //this actual line causes error , traces assembly code. thanks in advance can give me.
edit #1: if hit no debugging errors page shows like.
i in project
make temp file:
string reporttemppath = path.combine(path.gettemppath(), "pubreport" + guid.newguid().tostring() + ".html"); save content:
var root = new xelement(ns + "html", new xelement(ns + "head", new xelement(ns + "title", "publisher report"), // ...
var doctype = new xdocumenttype("html", "-//w3c//dtd xhtml 1.0 strict//en", "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd", null); var doc = new xdocument( new xdeclaration("1.0", "utf-8", "no"), doctype, root ); doc.save(path); then pass memorystream webbrowser control.
webbrowser1.documentstream = new memorystream(file.readallbytes(reporttemppath));
Comments
Post a Comment